#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
using namespace std;

int exp(string &s, int &i);
int term(string &s, int &i);
int factor(string &s, int &i);
int number(string &s, int &i);

int exp(string &s, int &i)
{
  int val = term(s, i);
  while(s[i] == '+' || s[i] == '-'){
    char op = s[i];
    i++;
    int val2 = term(s, i);
    if(op == '+') val += val2;
    else val -= val2;
  }
  return val;
}

int term(string &s, int &i)
{
  int val = factor(s, i);
  while(s[i] == '*' || s[i] == '/'){
    char op = s[i];
    i++;
    int val2 = factor(s, i);
    if(op == '*') val *= val2;
    else val /= val2;
  }
  return val;
}

int factor(string &s, int &i)
{
  if(isdigit(s[i]))
    return number(s, i);
  i++;
  int val = exp(s, i);
  i++;
  return val;
}

int number(string &s, int &i)
{
  int n = s[i] - '0';
  i++;
  while(isdigit(s[i])){
    n = n * 10 + (s[i] - '0');
    i++;
  }
  return n;
}

int main()
{
  int n;
  cin >> n;
  for(int j = 0; j < n; j++){
    string s;
    cin >> s;
    int i = 0;
    cout << exp(s, i) << endl;
  }
}