#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
vector<char> buf;
stack<char> tmp;
char t;
void add_buf(char x)
{
	buf.pb(x);
	return;
}
void add_tmp(char x)
{
	tmp.push(x);
	return;
}
void move()
{
	char x=tmp.top();
	tmp.pop();
	buf.pb(x);
	return;
}
void reset()
{
	while(1)
	{
		char x=tmp.top();
		if(x=='(')
		{
			tmp.pop();
			break;
		}
		buf.pb(x);
		tmp.pop();
	}
	return;
}
int priority(char x)
{
	if(x=='+'||x=='-')return 0;
	if(x=='*'||x=='/')return 1;
	if(x==')')return 2;
	if(x=='(')return 3;
	return 4;
}
void end()
{
	while(!tmp.empty())
	{
		char x=tmp.top();
		tmp.pop();
		buf.pb(x);
	}
	return;
}
bool is_num(char x)
{
	return priority(x)==4;
}
int calc()
{
	stack<char> c;
	for(int i=0;i<buf.size();i++)
	{
		if(is_num(buf[i]))
		{
			c.push(buf[i]-'0');
		}
		else
		{
			int a=c.top();
			c.pop();
			int b=c.top();
			c.pop();
			cout << a << ' '<< b << endl;
			switch(buf[i])
			{
				case '+':c.push(b+a);break;
				case '-':c.push(b-a);break;
				case '*':c.push(a*b);break;
				case '/':c.push(b/a);break;
			}
		}
	}
	return c.top();
}
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		buf.clear();
		while(!tmp.empty())
		{
			tmp.pop();
		}
		char s[101];
		scanf("%s",s);
		for(int i=0;i<strlen(s)-1;i++)
		{
			if(is_num(s[i]))
			{
				add_buf(s[i]);
				continue;
			}
			if(priority(s[i])==2)
			{
				reset();
				continue;
			}
			if(priority(s[i])==3)
			{
				add_tmp(s[i]);
				continue;
			}
			while(!tmp.empty())
			{
				if(priority(tmp.top())==1&&priority(s[i])==0)
				{
					move();
				}
				else break;
			}
			add_tmp(s[i]);
		}
		end();
		for(int i=0;i<buf.size();i++)
		{
			cout << buf[i] << ' ';
		}
		cout << endl;
		cout << calc() << endl;
	}
	return 0;
}