#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
#define el endl
#define int int64_t
#define fi first
#define se second
#define file(x) freopen(x".inp", "r", stdin); freopen(x".out", "w", stdout)
#define pb push_back
#define gd() ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rizzler signed main()
#define tc() int t; cin >> t; while(t--)
void tle() {
double time_taken = 1000.0 * clock() / CLOCKS_PER_SEC;
if (time_taken < 1000.0) {
std::cerr << "Time: ";
std::cerr << time_taken << "ms" << std::string(27, '\t');
} else {
std::cerr << "TLE Warning!\n";
std::cerr << "Time: ";
std::cerr << (time_taken / 1000.0) << "s" << std::string(27, '\n');
}
}
rizzler{
gd();
tc(){
int n; cin >> n;
string s; getline(cin >> ws, s);
vector<string> v;
stack<int> st;
stringstream ss(s);
string word;
while(ss >> word){
v.pb(word);
}
for (int i = 0; i < v.size(); i++){
if (isdigit(v[i].back())){
st.push(stoll(v[i]));
} else {
auto top2 = st.top(); st.pop();
auto top1 = st.top(); st.pop();
if (v[i] == "+"){
st.push(top1 + top2);
} else if (v[i] == "-"){
st.push(top1 - top2);
} else if (v[i] == "*"){
st.push(top1*top2);
} else {
st.push(top1/top2);
}
}
}
cout << st.top() << el;
}
tle();
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk8yIikKI3ByYWdtYSBHQ0MgdGFyZ2V0KCJhdngsYXZ4MixmbWEiKQojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdXNpbmcgbGwgPSBsb25nIGxvbmc7CmNvbnN0IGludCBtb2QgPSAxZTkgKyA3OwojZGVmaW5lIGVsIGVuZGwKI2RlZmluZSBpbnQgaW50NjRfdAojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgZmlsZSh4KSBmcmVvcGVuKHgiLmlucCIsICJyIi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nBiKHdvcmQpOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IHYuc2l6ZSgpOyBpKyspewogICAgICAgICAgICBpZiAoaXNkaWdpdCh2W2ldLmJhY2soKSkpewogICAgICAgICAgICAgICAgc3QucHVzaChzdG9sbCh2W2ldKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBhdXRvIHRvcDIgPSBzdC50b3AoKTsgc3QucG9wKCk7CiAgICAgICAgICAgICAgICBhdXRvIHRvcDEgPSBzdC50b3AoKTsgc3QucG9wKCk7CiAgICAgICAgICAgICAgICBpZiAodltpXSA9PSAiKyIpewogICAgICAgICAgICAgICAgICAgIHN0LnB1c2godG9wMSArIHRvcDIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh2W2ldID09ICItIil7CiAgICAgICAgICAgICAgICAgICAgc3QucHVzaCh0b3AxIC0gdG9wMik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHZbaV0gPT0gIioiKXsKICAgICAgICAgICAgICAgICAgICBzdC5wdXNoKHRvcDEqdG9wMik7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHN0LnB1c2godG9wMS90b3AyKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IHN0LnRvcCgpIDw8IGVsOwoKICAgIH0KCgogICAgdGxlKCk7CiAgICAKfQo=