#include<iostream>
#include<queue>
#include<string>
#include<cctype>
#include<cassert>
using namespace std;

class CAL{
private:
  string m_str;
  size_t m_cur;
  int digit();
  int number();
  int term();
  int expression();
  int factor();
  int calterm();
public:
  CAL(string str);
  int cal();
};

CAL::CAL(string str)
{
  m_str = str;
  m_cur = 0;
  m_str.resize(m_str.size() - 1);
}

int CAL::digit()
{
  assert(isdigit(m_str[m_cur]));
  int n = m_str[m_cur++] - '0';
  return n;
}

int CAL::number()
{
  int n = digit();
  while(m_cur < m_str.size() && isdigit(m_str[m_cur]))
    n = n*10 + digit();
  return n;
}

int CAL::term()
{
  int a = number();
  while(m_cur < m_str.size() && (m_str[m_cur] == '*' || m_str[m_cur] == '/')){
    char op = m_str[m_cur++];
    int b = number();
    if(op == '*') a *= b; else if(op == '/') a /= b;
  }
  return a;
}

int CAL::expression()
{
  int a = term();
  while(m_cur < m_str.size() && (m_str[m_cur] == '+' || m_str[m_cur] == '-')){
    char op = m_str[m_cur++];
    int b = term();
    if(op == '+') a += b; else if(op == '-') a -= b;
  }
  return a;
}

int CAL::factor()
{
  if(m_str[m_cur] != '(') return number();
  m_cur += 1;
  int n = expression();
  assert(m_str[m_cur] == ')');
  m_cur += 1;
  return n;
}

int CAL::calterm()
{
  int a = factor();
  while(m_cur < m_str.size() && (m_str[m_cur] == '*' || m_str[m_cur] == '/')){
    char op = m_str[m_cur++];
    int b = factor();
    if(op == '*') a *= b; else if(op == '/') a /= b;
  }
  return a;
}

int CAL::cal()
{
  int a = calterm();
  while(m_cur < m_str.size() && (m_str[m_cur] == '+' || m_str[m_cur] == '-')){
    char op = m_str[m_cur++];
    int b = calterm();
    if(op == '+') a += b; else if(op == '-') a -= b;
  }
  return a;
}

int main()
{
  int N;
  cin >> N;
  queue<int> answer;
  string str;
  for(int i = 0; i < N; ++i){
    cin >> str;
    CAL a(str);
    answer.push(a.cal());
  }
  while(!answer.empty()){
    cout << answer.front() << endl;
    answer.pop();
  }
}