#include<stdio.h> main() { int b,a,t; char s[50],ch; scanf("%d\n",&t); while(t--) { b=a=0; scanf("%c",&ch); while(ch!='\n') { if(ch=='F') a++; if(ch=='M') b++; scanf("%c",&ch); } if(b==a) printf("LOOP\n"); else printf("NO LOOP\n"); } }