#include<iostream>
#include<cassert>
using namespace std;
string s;
size_t cur=0;
int digit()
{
    assert(isdigit(s[cur]));
    int n=s[cur]-'0';
    cur=cur+1;
    return n;
};
int number()
{
    int n=digit();
    while(cur<s.size()&&isdigit(s[cur]))
        n=n*10+digit();
    return n;
};
double expression();
double factor()
{
    if(s[cur]!='(')
        return number();
    cur++;
    double n=expression();
    assert(s[cur]==')');
    cur++;
    return n;
};
double term()
{
    double a=factor();
    while(cur<s.size()&&(s[cur]=='*'||s[cur]=='/'))
    {
        char op=s[cur++];
        int b=factor();
        if(op=='*')
            a*=b;
        else
            a/=b;
    }
    return a;
};


int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cur=0;
        cin>>s;
        s.resize(s.size()-1);
        cout<<expression()<<endl;
    }
}

double expression()
{
    int a=term();
    while((cur<s.size())&&(s[cur]=='+'||s[cur]=='-'))
    {
        char op=s[cur++];
        int b=term();
        if(op=='+')
            a+=b;
        else
            a-=b;
    }
    return a;
}