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