#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int tests, track[2], temp;
  for (scanf("%d\n", &tests); tests--;) {
    int m = 0, f = 0;
    while (1) {
      track[0] = getchar();
      track[1] = getchar();
      m += (track[0] == 'M') + (track[1] == 'M');
      f += (track[0] == 'F') + (track[1] == 'F');
      if (getchar() == '\n')
        break;
    }
    if (m > 1 && f > 1 && m == f) {
      puts("LOOP");
    } else {
      puts("NO LOOP");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     122c <main+0xfc>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x4d,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x4d,-0xc(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x46,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x46,-0xc(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
jne    11e5 <main+0xb5>
jmp    11ea <main+0xba>
jmp    1171 <main+0x41>
cmpl   $0x1,-0x18(%rbp)
jle    121b <main+0xeb>
cmpl   $0x1,-0x1c(%rbp)
jle    121b <main+0xeb>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    121b <main+0xeb>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
jmp    1227 <main+0xf7>
lea    0xde2(%rip),%rdi
call   1030 <puts@plt>
jmp    114f <main+0x1f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xee0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    115d <main+0x2d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
pxor   %xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
lea    0xeb9(%rip),%r14
lea    0xeaf(%rip),%r15
jmp    119d <main+0x6d>
nopw   0x0(%rax,%rax,1)
cmp    $0x2,%eax
cmovb  %r15,%rdi
call   1030 <puts@plt>
subl   $0x1,0xc(%rsp)
pxor   %xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
jb     1151 <main+0x21>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
movzbl %bl,%ecx
movd   %ecx,%xmm0
punpcklbw %xmm0,%xmm0
movdqa 0xe40(%rip),%xmm2
pcmpeqb %xmm2,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0xd4,%xmm0,%xmm0
movdqa 0xe3b(%rip),%xmm3
pand   %xmm3,%xmm0
paddd  0x10(%rsp),%xmm0
movzbl %al,%eax
movd   %eax,%xmm1
punpcklbw %xmm1,%xmm1
pcmpeqb %xmm2,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0xd4,%xmm1,%xmm1
pand   %xmm3,%xmm1
paddd  %xmm0,%xmm1
movdqa %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    119d <main+0x6d>
movdqa 0x10(%rsp),%xmm0
movd   %xmm0,%eax
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%ecx
mov    %r14,%rdi
cmp    %ecx,%eax
je     122d <main+0xfd>
mov    %r15,%rdi
cmp    $0x2,%ecx
jae    1180 <main+0x50>
mov    %r15,%rdi
jmp    1180 <main+0x50>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"LOOP\00"
@.str.2 = [8 x i8] c"NO LOOP\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %61, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %62
12: ; preds = %8
store i32 0, i32* %5
store i32 0, i32* %6
br label %13
13: ; preds = %12, %46
%14 = call signext i8 (...) @getchar()
%15 = sext i8 %14 to i32
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %15, i32* %16
%17 = call signext i8 (...) @getchar()
%18 = sext i8 %17 to i32
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %18, i32* %19
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 77
%23 = zext i1 %22 to i32
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 77
%27 = zext i1 %26 to i32
%28 = add nsw i32 %23, %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, %28
store i32 %30, i32* %5
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 70
%34 = zext i1 %33 to i32
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 70
%38 = zext i1 %37 to i32
%39 = add nsw i32 %34, %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, %39
store i32 %41, i32* %6
%42 = call signext i8 (...) @getchar()
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %46
45: ; preds = %13
br label %47
46: ; preds = %13
br label %13
47: ; preds = %45
%48 = load i32, i32* %5
%49 = icmp sgt i32 %48, 1
br i1 %49, label %50, label %59
50: ; preds = %47
%51 = load i32, i32* %6
%52 = icmp sgt i32 %51, 1
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %61
59: ; preds = %53, %50, %47
%60 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %8
62: ; preds = %8
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"LOOP\00"
@.str.2 = [8 x i8] c"NO LOOP\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = add nsw i32 %4, -1
store i32 %5, i32* %1
%6 = icmp eq i32 %4, 0
br i1 %6, label %38, label %7
7: ; preds = %0, %23
%8 = phi <2 x i32> [ %24, %23 ], [ zeroinitializer, %0 ]
%9 = call signext i8 (...) @getchar()
%10 = call signext i8 (...) @getchar()
%11 = insertelement <2 x i8> poison, i8 %9, i64 0
%12 = shufflevector <2 x i8> %11, <2 x i8> poison, <2 x i32> zeroinitializer
%13 = icmp eq <2 x i8> %12, <i8 77, i8 70>
%14 = zext <2 x i1> %13 to <2 x i32>
%15 = insertelement <2 x i8> poison, i8 %10, i64 0
%16 = shufflevector <2 x i8> %15, <2 x i8> poison, <2 x i32> zeroinitializer
%17 = icmp eq <2 x i8> %16, <i8 77, i8 70>
%18 = zext <2 x i1> %17 to <2 x i32>
%19 = add <2 x i32> %8, %14
%20 = add <2 x i32> %19, %18
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
br i1 %22, label %25, label %23
23: ; preds = %7, %25
%24 = phi <2 x i32> [ %20, %7 ], [ zeroinitializer, %25 ]
br label %7
25: ; preds = %7
%26 = extractelement <2 x i32> %20, i64 0
%27 = icmp ugt i32 %26, 1
%28 = extractelement <2 x i32> %20, i64 1
%29 = icmp ugt i32 %28, 1
%30 = select i1 %27, i1 %29, i1 false
%31 = icmp eq i32 %26, %28
%32 = select i1 %30, i1 %31, i1 false
%33 = select i1 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%34 = call i32 @puts(i8* dereferenceable(1) %33)
%35 = load i32, i32* %1
%36 = add nsw i32 %35, -1
store i32 %36, i32* %1
%37 = icmp eq i32 %35, 0
br i1 %37, label %38, label %23
38: ; preds = %25, %0
ret i32 0
}