#28594: _CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)


#include <iostream>
#include <sstream>
using namespace std;

int main() {
int t;
string s;
char head, tail, pre;
cin >> t;
getline(cin, s);
while (t--){
bool loop=true;
int len=1;
getline(cin, s);
head=s[0];
tail=s[s.size()-1];
if (head==tail){
cout <<"NO LOOP\n";
continue;
}
stringstream ss(s);
string x;
ss >> x;
pre=x[1];
while (ss >> x){
len++;
if (pre==x[0]){
loop=false;
break;
}
pre=x[1];
}
if (len>1 && loop){
cout <<"LOOP\n";
}
else {
cout <<"NO LOOP\n";
}
}
}