#include <bits/stdc++.h>
#define MAXN 105
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--) {
string str;
cin >> str;
vector<int> nums;
vector<char> ops;
for (int i = 0; i < str.length(); i++) {
if (i & 1)
ops.push_back(str[i]);
else
nums.push_back((int)(str[i] - '0'));
}
vector<vector<long long> > max_cost(nums.size() + 1, vector<long long>(nums.size() + 1, 0));
vector<vector<long long> > min_cost(nums.size() + 1, vector<long long>(nums.size() + 1, LLONG_MAX));
for (int i = 0; i <= nums.size(); i++)
max_cost[i][i] = min_cost[i][i] = nums[i];
for (int l = 2; l < nums.size() + 1; l++) {
for (int i = 0; i < nums.size() - l + 1; i++) {
int j = i + l - 1;
for (int k = i; k < j; k++) {
long long tmp_mx, tmp_mn;
if (ops[k] == '+') {
tmp_mn = min_cost[i][k] + min_cost[k + 1][j];
tmp_mx = max_cost[i][k] + max_cost[k + 1][j];
}
else {
tmp_mn = min_cost[i][k] * min_cost[k + 1][j];
tmp_mx = max_cost[i][k] * max_cost[k + 1][j];
}
min_cost[i][j] = min(min_cost[i][j], tmp_mn);
max_cost[i][j] = max(max_cost[i][j], tmp_mx);
}
}
}
printf("%lld %lld\n", max_cost[0][nums.size()-1], min_cost[0][nums.size()-1]);
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTUFYTiAxMDUKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewoJaW50IHQ7CglzY2FuZigiJWQiLCAmdCk7Cgl3aGlsZSAodC0tKSB7CgkJc3RyaW5nIHN0cjsKCQljaW4gPj4gc3RyOwoKCQl2ZWN0b3I8aW50PiBudW1zOwoJCXZlY3RvcjxjaGFyPiBvcHM7CgkJZm9yIChpbnQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoKCk7IGkrKykgewoJCQlpZiAoaSAmIDEpCgkJCQlvcHMucHVzaF9iYWNrKHN0cltpXSk7CgkJCWVsc2UKCQkJCW51bXMucHVzaF9iYWNrKChpb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