
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#include <cmath>
#include <cassert>
#define INF 10000000000
#define MOD 10000000007
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> i_i;

string S;
size_t cur = 0;

//with ()*************************************************************************************

int factor();

bool isdigit(char a){
    if (a == '0' or a == '1' or a == '2' or a == '3' or a == '4' or a == '5' or a == '6' or a == '7' or a == '8' or a == '9') {
        return true;
    }
    return false;
}

//********************************************************************************************

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

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

int term(){
    //*****************************************************************************************
    int a = factor();
    //*****************************************************************************************
    //int a = number();
    while (cur < S.size() and (S[cur]=='*' or S[cur]=='/')) {
        char op = S[cur++];
        //int b = number();
        //*****************************************************************************************
        int b = factor();
        //*****************************************************************************************
        if(op=='*')a *= b; else a/=b;
    }
    return a;
}

int expression(){
    int a = term();
    while (cur < S.size() and (S[cur] == '+' or S[cur] == '-')) {
        char op = S[cur++];
        int b = term();
        if(op == '+') a += b; else a -= b;
    }
    return a;
}

//with() *************************************************************************************
int factor(){
    if(S[cur] != '(') return number();
    cur++;
    int n = expression();
    assert(S[cur] == ')');
    cur++;
    return n;
}
//********************************************************************************************

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        cur = 0;
        cin >> S;
        S.resize(S.length()-1);
        cout << expression()<<endl;
    }
}