#13,#14,#17,#18,#19,#20,#21WA
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string op[1005];
long long a[1005],b[1005],c[1005],d[1005],e[1005];
for(int i=0;i<n;i++){
cin>>op[i];
int c1=0,c2=0;
char ch[30];
bool f=0;
cin>>a[i]>>ch[0]>>b[i]>>ch[1]>>c[i]>>ch[2]>>d[i]>>ch[3]>>e[i];
for(int j=0;j<strlen(ch);j++){
if(ch[j]=='.')c1++;
if(ch[j]==':')c2++;
}
if(c1>3||c2>1||a[i]>255||b[i]>255||c[i]>255||d[i]>255||e[i]>65535){
cout<<"ERR"<<endl;
f=1;
}
if(!f){
if(op[i]=="Server"){
bool f2=0;
for(int j=0;j<i;j++){
if(a[i]==a[j]&&b[i]==b[j]&&c[i]==c[j]&&d[i]==d[j]&&e[i]==e[j]&&op[j]=="Server"){
cout<<"FAIL"<<endl;
f2=1;
break;
}
}
if(!f2)
cout<<"OK"<<endl;
}
if(op[i]=="Client"){
bool f2=0;
for(int j=0;j<i;j++){
if(a[i]==a[j]&&b[i]==b[j]&&c[i]==c[j]&&
d[i]==d[j]&&e[i]==e[j]&&op[j]=="Server"){
cout<<j+1<<endl;
f2=1;
break;
}
}
if(!f2)
cout<<"FAIL"<<endl;
}
}
}
return 0;
}