#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	int t;
	cin >> t;
	cin.ignore();
	while (t--){
        string tokens;
        cin >> tokens;
		stack<string> st;
		for (int i = 0; i <= tokens.size() - 1; i++) {
            if (tokens[i] == '+') {
                string a = st.top(); st.pop();
                string b = st.top(); st.pop();
                st.push("(" + b + "+" + a + ")");
            }
            else if (tokens[i] == '-') {
                string a = st.top(); st.pop();
                string b = st.top(); st.pop();
                st.push("(" + b + "-" + a + ")");
            }
            else if (tokens[i] == '*') {
                string a = st.top(); st.pop();
                string b = st.top(); st.pop();
                st.push("(" + b + "*" + a + ")");
            }
            else if (tokens[i] == '/') {
                string a = st.top(); st.pop();
                string b = st.top(); st.pop();
                st.push("(" + b + "/" + a + ")");
            }
            else {
            	 st.push(string(1,tokens[i]));
			}
		}
			if (st.size() == 1) {
            cout << st.top() << endl;
        }
}

}

