#include <bits/stdc++.h>
using namespace std;
string toString(__int128 x) {
if(x == 0) return "0";
bool neg = false;
if(x < 0) { neg = true; x = -x; }
string s;
while(x > 0) {
int digit = (int)(x % 10);
s.push_back('0' + digit);
x /= 10;
}
if(neg) s.push_back('-');
reverse(s.begin(), s.end());
return s;
}
// Structure representing one pair of gates.
struct GatePair {
char opL, opR; // either '+' or 'x'
int a, b;
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<GatePair> pairs(n);
for (int i = 0; i < n; i++){
cin >> pairs[i].opL >> pairs[i].a >> pairs[i].opR >> pairs[i].b;
}
// dp after all pairs: dp(L, R) = L + R -> coefficients: A = 1, B = 1, C = 0.
__int128 A = 1, B = 1, C = 0;
// Process gate pairs in reverse.
for (int i = n-1; i >= 0; i--){
char opL = pairs[i].opL, opR = pairs[i].opR;
int paramL = pairs[i].a, paramR = pairs[i].b;
__int128 nA, nB, nC;
bool leftBetter = (A >= B); // decision: bonus allocation will weight the lane with higher sensitivity.
if(opL == '+' && opR == '+'){
// Both additions: bonus_total = paramL + paramR (a constant)
if(leftBetter){
nA = A;
nB = B;
nC = C + A * (paramL + paramR);
} else {
nA = A;
nB = B;
nC = C + B * (paramL + paramR);
}
} else if(opL == 'x' && opR == '+'){
// Left multiplication and right addition.
// bonus_total = (paramL - 1)*L + paramR.
if(leftBetter){
nA = A * paramL;
nB = B;
nC = C + A * paramR;
} else {
nA = A + B * (paramL - 1);
nB = B;
nC = C + B * paramR;
}
} else if(opL == '+' && opR == 'x'){
// Left addition and right multiplication.
// bonus_total = paramL + (paramR - 1)*R.
if(leftBetter){
nA = A;
nB = B + A * (paramR - 1);
nC = C + A * paramL;
} else {
nA = A;
nB = B * paramR;
nC = C + B * paramL;
}
}
else if(opL == 'x' && opR == 'x'){
if(leftBetter){
nA = A * paramL;
nB = B + A * (paramR - 1);
nC = C;
} else {
nA = A + B * (paramL - 1);
nB = B * paramR;
nC = C;
}
}
A = nA; B = nB; C = nC;
}
long long ans = A + B + C;
cout << ans << "\n";
}
return 0;
}