z,t,s;main(x){for(gets(&z);(z=~getchar())?z+11?z+83?x=z,z+88?s--,~t&&t++:~s&&s++:t--:(puts("impossible"+2*!(t|s<0|x+72)),s=t=0),1:0;);}