#include/*math=math*/ // AOC 2020 DAY 18 SYMBOLS // char*p,*q,b[324];long f,z,d(), e();; long x(){long(*g)()=f ?e:d, a=g(),b,i;for(;*p==+1 ||(!f &&*p==2);b=g(),i?a+=+ + b:(a*=b))i=*p++== + 2;return +a;}long d(){{ long a=7<=*p&&*p<=16? *p-7: (++p,+x());++p;return +a;}} long e (){ long a=d();for(;*p==2 ; a+=d( ))++p;return ((a) );}int main(int c,char**g ){for(f =--c>0;q=gets(b); *p=0,p =b,z+=x())for(p= b ;*q;q ++)*q^32?*p++=( *q) -4*9 -5:0;printf("%ld\n",z);/*18*/}