#include <iostream>
#include <cassert>
#include <string>

using namespace std;

string calc;
int cur;
int digit();
int number();
int expression();
int term();
int factor();

int main(){
  int num,i;
  cin >> num;
  for (i = 0; i < num; ++i){
    cin >> calc;
    calc.resize(calc.size()-1);
    cur = 0;

    cout << calc << endl;
    cout << expression() << endl;
  }
}

int digit(){
  assert(isdigit(calc[cur]));
  int n = calc[cur] - '0';
  cur++;
  return n;
}

int number(){
  int n = digit();
  while(cur<calc.size() && isdigit(calc[cur])){
    n = n*10 + digit();
  }
  return n;
}

int expression(){
  int sum = term(); 
  while((cur < calc.size())&&(calc[cur]=='+'||calc[cur]=='-')){
    char op = calc[cur];
    cur++; // will look at the next num after op
    int b = term();
    if(op == '+'){
      sum += b;
    }else{
      sum -= b;
    }
  }
  return sum;
}

int term(){
  int a = factor();
  while((cur < calc.size())&&(calc[cur]=='*'||calc[cur]=='/')){
    char op = calc[cur];
    cur++; // will look at the next num after op
    int b = factor();
    if(op == '*'){
      a *= b;
    }else{
      a /= b;
    }
  }
  return a;
}

int factor(){
  if(calc[cur] != '('){
    return number();
  }else{
    cur++;
    int n = expression();
    assert(calc[cur] == ')');
    cur++;
    return n;
  }
}