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