#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e4;
int n;
unordered_map<string,bool> m2;
unordered_map<string,int> m3;
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
string s;
bool cc=0;
cin>>s;
if(s[0]=='S') cc=1;
else cc=0;
int a,b,c,d,e;
char c1,c2,c3,c4;
scanf("%d%c%d%c%d%c%d%c%d",&a,&c1,&b,&c2,&c,&c3,&d,&c4,&e);
if(a>255||b>255||c>255||d>255||e>65535||c1!='.'||c2!='.'||c3!='.'||c4!=':'){
cout<<"ERR\n";
continue;
}
string ip=to_string(a)+"."+to_string(b)+"."+to_string(c)+"."+to_string(d)+":"+to_string(e);
if(cc==1){
if(m2[ip]==1){
cout<<"FAIL\n";
}else{
m2[ip]=1;
m3[ip]=i;
cout<<"OK\n";
}
continue;
}
if(cc==0){
if(m2[ip]==1){
cout<<m3[ip]<<"\n";
}else{
cout<<"FAIL\n";
}
}
}
return 0;
}