#include #include #include using namespace std; const int base=10000; const int width=4; const int N=1300; struct bint { int ln,v[N]; bint(int r=0) { for(ln=0;r>0;r/=base) v[ln++]=r%base; } bint operator = (const bint& r) { memcpy(this,&r,(r.ln+1)*sizeof(int)); } }; bool operator < (const bint& a,const bint& b) { int i; if(a.ln!=b.ln) return a.ln=0&&a.v[i]==b.v[i];i--); return i<0?0:a.v[i]0;i++) { if(i0;j++,cy/=base) { if(j=res.ln) res.v[res.ln++]=cy%base; else res.v[i+j]=cy%base; } return res; } void write(const bint& v) { int i; printf("%d",v.ln==0?0:v.v[v.ln-1]); for(i=v.ln-2;i>=0;i--) printf("%04d",v.v[i]); printf("\n"); } char buf[10]; bint b[10]; struct o { int a,b,o; }o[400000]; bool flag[10],cal[400000]; int main() { for(int i=0;i<10;i++) b[i]=1; int i=0; while(scanf("%s",buf)!=EOF&&buf[0]!='#') { o[i].a=buf[0]-'A'; if(buf[1]=='+') o[i].o=0,o[i].b=buf[3]-'A'; else if(buf[1]=='*') o[i].o=1,o[i].b=buf[3]-'A'; else o[i].o=2,o[i].b=buf[2]-'A'; i++; } for(int j=0;j<10;j++) flag[j]=true; for(int j=i-1;j>=0;j--) { cal[j]=flag[o[j].a]; if(o[j].o==2) flag[o[j].a]=false,flag[o[j].b]=true; } for(int j=0;j