#include<iostream> #include<string> #include<cmath> using namespace std;
int Case; char in[400];
int main() { cin>>Case; int pos; int i,j,k,m,n,len,cur,sumint_left,sumint_right,sumx_left,sumx_right; float sumx,sumint; float res; bool left; bool lastchar; while(Case--) { cin>>in; len=strlen(in); sumint_left=0; sumint_right=0; sumx_left=0; sumx_right=0; cur=0; left=1; for(i=0;i<len;i++) if(in[i]=='=') break; pos=i; lastchar=1; for(i=0;i<pos;i++) { if(in[i]=='x') { if(lastchar) sumx_left++; else sumx_left--; i++; if(i==pos) break; else if(in[i]=='+') lastchar=1; else lastchar=0; } else { cur=0; for(j=i;j<pos&&in[j]>='0' && in[j]<='9';j++) { cur*=10; cur+=in[j]-'0'; } if(j==pos) { if(lastchar) sumint_left+=cur; else sumint_left-=cur; break; } else { if(in[j]=='x') { if(lastchar) sumx_left+=cur; else sumx_left-=cur; j++; if(j==pos) break; else if(in[j]=='+') lastchar=1; else lastchar=0; i=j; } else { if(lastchar) sumint_left+=cur; else sumint_left-=cur; if(in[j]=='+') lastchar=1; else lastchar=0; i=j; } } } } lastchar=1; for(i=pos+1;i<len;i++) { if(in[i]=='x') { if(lastchar) sumx_right++; else sumx_right--; i++; if(i==len) break; else if(in[i]=='+') lastchar=1; else lastchar=0; } else { cur=0; for(j=i;j<len && in[j]<='9' && in[j]>='0';j++) { cur*=10; cur+=in[j]-'0'; } if(j==len) { if(lastchar) sumint_right+=cur; else sumint_right-=cur; break; } else { if(in[j]=='x') { if(lastchar) sumx_right+=cur; else sumx_right-=cur; j++; if(j==pos) break; else if(in[j]=='+') lastchar=1; else lastchar=0; i=j; } else { if(lastchar) sumint_right+=cur; else sumint_right-=cur; if(in[j]=='+') lastchar=1; else lastchar=0; i=j; } } } } // cout<<sumx_left<<" "<<sumx_right<<" "<<sumint_left<<" "<<sumint_right<<endl; if(sumx_left==sumx_right) { if(sumint_left==sumint_right) cout<<"IDENTITY"<<endl; else cout<<"IMPOSSIBLE"<<endl; } else { sumx=sumx_left-sumx_right; sumint=sumint_right-sumint_left; res=sumint/sumx; cout<<floor(res)<<endl; } } return 0; }
|