#include <iostream>

using namespace std;

#define isNumber(c) (c >= '0' && c <= '9')

class Stack

{

public:

Stack();

void push(int n);

long long pop();

long long point;

long long data[32];

};

Stack::Stack()

{

point = 0;

}

void Stack::push(int n)

{

data[point++] = n;

}

long long Stack::pop()

{

return data[--point];

}

long long max(char str[128])

{

long long n = 0;

Stack *s = new Stack();

for (int i = 0;str

*!= '\0';i++)*

{

if (isNumber(str

{

if (isNumber(str

*))*

{

n = str{

n = str

*- '0';*

if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + strif (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str

*- '0';*

}

s->push(n);

}

else

{

if (str}

s->push(n);

}

else

{

if (str

*== '+')*

{

i++;

n = str{

i++;

n = str

*- '0';*

if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + strif (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str

*- '0';*

}

n += s->pop();

s->push(n);

}

}

}

n = 1;

for (int j = 0;j < s->point;j++)

{

n *= s->data[j];

}

delete s;

return n;

}

int min(char str[128])

{

long long n = 0;

Stack *s = new Stack();

for (int i = 0;str}

n += s->pop();

s->push(n);

}

}

}

n = 1;

for (int j = 0;j < s->point;j++)

{

n *= s->data[j];

}

delete s;

return n;

}

int min(char str[128])

{

long long n = 0;

Stack *s = new Stack();

for (int i = 0;str

*!= '\0';i++)*

{

if (isNumber(str{

if (isNumber(str

*))*

{

n = str{

n = str

*- '0';*

if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str[i] - '0';

}

s->push(n);

}

else

{

if (str[i] == '*')

{

i++;

n = str[i] - '0';

if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str[i] - '0';

}

n *= s->pop();

s->push(n);

}

}

}

n = 0;

for (int j = 0;j < s->point;j++)

{

n += s->data[j];

}

delete s;

return n;

}

int main()

{

int n;

char str[128] = "";

cin >> n;

cin.getline(str,128);

while(n--)

{

cin.getline(str,128);

cout << "The maximum and minimum are " << max(str) << " and " << min(str) << '.' << endl;

}

return 0;

}[/cpp]if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str[i] - '0';

}

s->push(n);

}

else

{

if (str[i] == '*')

{

i++;

n = str[i] - '0';

if (isNumber(str[i + 1]))

{

i++;

n = n * 10 + str[i] - '0';

}

n *= s->pop();

s->push(n);

}

}

}

n = 0;

for (int j = 0;j < s->point;j++)

{

n += s->data[j];

}

delete s;

return n;

}

int main()

{

int n;

char str[128] = "";

cin >> n;

cin.getline(str,128);

while(n--)

{

cin.getline(str,128);

cout << "The maximum and minimum are " << max(str) << " and " << min(str) << '.' << endl;

}

return 0;

}[/cpp]