#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#define M 500
using namespace std;
long long deal(char *str,char a,char b)
{
stack<char>operat;
stack<long long>num;
long long len = strlen(str);
long long flage = 0;
long long n;
char ope;
for(long long i = 0;i < len;i++)
{
if(!flage){
sscanf(&str[i],"%lld",&n);
num.push(n);
if(n >= 10) i++;
flage = 1;
}
else{
ope = str[i];
flage = 0;
if(!operat.empty())
{
char cal = operat.top();
long long x,y;
if(ope == b || cal == a){
operat.pop();
x = num.top();num.pop();
y = num.top();num.pop();
long long r;
if(cal == '*')
r = x * y;
else r = x + y;
num.push(r);
}
operat.push(ope);
}
else operat.push(ope);
}
}
while(!operat.empty())
{
char cal = operat.top();
operat.pop();
long long x,y;
x = num.top(); num.pop();
y = num.top(); num.pop();
long long r;
if(cal == '*')
r = x * y;
else r = x + y;
num.push(r);
}
return num.top();
}
int main()
{
//freopen("in.in","r",stdin);
long long T;
long long minv,maxv;
char str[M];
scanf("%lld",&T); getchar();
while(T--)
{
gets(str);
minv = deal(str,'*','+');
maxv = deal(str,'+','*');
printf("The maximum and minimum are %lld and %lld.\n",maxv,minv);
}
return 0;
}