#include<iostream>
#include<cctype>
#define I int
I E();std::string S;I P,V;I T(){for(V=0;isdigit(S[P]);)V=V*10+S[P++]-48;return S[P]-40?V:++P?E():0;}I F(){I a=T();for(;S[P]==42|S[P]==47;)a=S[P++]-47?a*=T():a/=T();return a;}I E(){I a=F();for(;S[P]==43|S[P]==45;)a+=-(S[P++]==45)*F();return a;}main(){for(std::cin>>P;std::cin>>S;printf("%d\n",E()))S[S.size()-1]=P=0;}