
#include <iostream>
#include <string>
#include <cctype>/////////////////////////////////////
#include <memory>
class Parser{

private:
    
    typedef std::string::const_iterator State;
public:
    Parser(){

    }
    ~Parser(){}

    long long int parse(std::string o_s){
        std::string::const_iterator s=o_s.begin();


        return expression(s);
    }
    long long int num_or_brackets(State &b){
        long long int result=-1;
        if(*b=='('){
            b++;
            result=expression(b);
            if(*b==')'){
                b++;
            }else{
                std::cout << "括弧の対応が正しくありません" << std::endl;
            }
        }else if(isdigit(*b)){
            result=number(b);
        }else if(*b==')'){
            std::cout << "括弧の対応が正しくありません" << std::endl;
        }else{
            std::cout << "数式に数字，記号以外のものが含まれています: "<<*b << std::endl;
            return -1;
        }
        return result;
    }
    long long int number(State &b){
        long long int result = 0;
        while(isdigit(*b)){
            result *= 10;
            result += (long long int)(*b - '0');
            b++;
        }
        return result;
    }
    long long int term(State &b){
        long long int result=num_or_brackets(b);
        while(1){
            if(*b=='*'){
                b++;
                result *= num_or_brackets(b);

            }else if(*b=='/'){
                b++;
                result /= num_or_brackets(b);
            }else{
                break;
            }
        }
        //std::cout << result << std::endl;
        return result;
    }
    long long int expression(State &b){
        long long int result;
        if(*b=='-'){
            result = -term(b);
        }else{
            result = term(b);


        }
        while(*b!='\0'){
            if(*b=='+'){
                b++;
                result += term(b);
            }else if(*b=='-'){
                b++;
                result -= term(b);
            }else if(*b==')'||*b=='='){
                return result;
            }else{
                std::cout << "数式に数字，記号以外のものが含まれています: "<<*b << std::endl;
                return -1;
            }
        }
        return result;
    }



};


int main(){
    std::unique_ptr<Parser> parser(new(Parser));
    long long int n;
    std::cin >> n;
    std::string s;

    for (long long int i=0; i < n; i++)
    {

        std::cin >> s;
        std::cout<<parser->parse(s)<<std::endl;
    }
    return 0;
}

