#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <climits>
#include <cmath>
#include <cassert>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define ll long long
using namespace std;

string m;
int point = 0;
ll term(void);

bool left() {
    if(point < m.size()) return true;
    else return false;
}

char peek() {
    return m[point];
} 

char pop() {
    return m[point++];
}

void eat(char ch) {
    assert(left() && pop() == ch);
}

ll expr() {
    ll res = term();
    while(left() && (peek() == '+' || peek() == '-')) {
        if(peek() == '+') {
            eat('+');
            res += term();
        } else {
            eat('-');
            res -= term();
        }
    }
    return res;
}

ll number() {
    ll res = 0;
    while(left() && isdigit(peek())) {
        res *= 10;
        res += pop() - '0';
    }
    return res;
}

ll factor() {
    if(peek() == '('){
        eat('(');
        ll res = expr();
        eat(')');
        return res;
    } else {
        return number();
    }
}

ll term() {
    ll res = factor();
    while(left() && (peek() == '*' || peek() == '/')) {
        if(peek() == '*') {
            eat('*');
            res *= factor();
        } else {
            eat('/');
            res /= factor();
        }
    }
    return res;
}

int main(void){
    int n;
    ll ans;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n) {
        cin >> m;
        point = 0;
        ans = expr();
        cout << ans << endl;
        eat('=');
    }
}
