#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

// <expression> := <fomula>( ( '+' | '-' )<fomula> )+ '='
// <fomula> := <atom>( ( '*' | '/' )<atom> )+
// <atom> := '('<expression>')' | <number>
// <number> := ( '0' | '1' | ... | '9' )+

PII expression( const string &, int p );
PII fomula( const string &, int p );
PII atom( const string &, int p );
PII number( const string &, int p );

PII expression( const string &s, int p = 0 )
{
	PII res = fomula( s, p );
	while ( string( "+-" ).find( s[ res.snd ] ) != string::npos )
	{
		PII r = fomula( s, res.snd + 1 );
		res.fst += ( s[ res.snd ] == '+' ? 1 : -1 ) * r.fst;
		res.snd = r.snd;
	}
	return res;
}

PII fomula( const string &s, int p = 0 )
{
	PII res = atom( s, p );
	while ( string( "*/" ).find( s[ res.snd ] ) != string::npos )
	{
		PII r = s[ res.snd + 1 ] == '(' ? expression( s, res.snd + 2 ) : number( s, res.snd + 1 );
		if ( s[ res.snd ] == '*' )
		{
			res.fst *= r.fst;
		}
		else
		{
			res.fst /= r.fst;
		}
		res.snd = r.snd;
	}
	return res;
}

PII atom( const string &s, const int p = 0 )
{
	if ( s[p] == '(' )
	{
		PII res = expression( s, p + 1 );
		res.snd ++;
		return res;
	}
	else
	{
		return number( s, p );
	}
}

PII number( const string &s, int p )
{
	int res = 0;
	while ( isdigit( s[p] ) )
	{
		res *= 10;
		res += s[ p++ ] - '0';
	}
	return MP( res, p );
}

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int n;
	cin >> n;

	REP( i, 0, n )
	{
		string line;
		cin >> line;
		cout << expression( line ).fst << endl;
	}

	return 0;
}