#include <iostream>
#include <stack>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main() {
    int t;
    cin >> t;
    cin.ignore(); // skip newline after t

    while (t--) {
        int n;
        cin >> n;
        cin.ignore(); // skip newline after n

        string line;
        getline(cin, line); // read the full expression

        // Tokenize
        vector<string> tokens;
        stringstream ss(line);
        string token;
        while (ss >> token) {
            tokens.push_back(token);
        }

        if (tokens.size() != n) {
            cout << "Invalid Expression" << endl;
            continue;
        }

        stack<long long> st;
        bool valid = true;

        for (int i = tokens.size() - 1; i >= 0; --i) {
            string tok = tokens[i];

            if (isdigit(tok[0]) || (tok[0] == '-' && tok.size() > 1)) {
                // valid number
                st.push(stoll(tok));
            } else if (tok == "+" || tok == "-" || tok == "*" || tok == "/") {
                if (st.size() < 2) {
                    valid = false;
                    break;
                }
                long long a = st.top(); st.pop();
                long long b = st.top(); st.pop();

                if (tok == "+") st.push(a + b);
                else if (tok == "-") st.push(a - b);
                else if (tok == "*") st.push(a * b);
                else if (tok == "/") {
                    if (b == 0) {
                        valid = false;
                        break;
                    }
                    st.push(a / b);
                }
            } else {
                valid = false;
                break;
            }
        }

        if (valid && st.size() == 1) {
            cout << st.top() << endl;
        } else {
            cout << "Invalid Expression" << endl;
        }
    }

    return 0;
}
