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