#include<bits/stdc++.h>
using namespace std;
string b[1000];
int c[1000];
char ch[6];
bool pd(string IP){
if(IP[0]=='.'||IP[0]==':')return 0;
int a[10]={0,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int x=0,y=0,z=1;
int len=IP.size();
for(int i=0;i<len;i++){
if(IP[i]>='0'&&IP[i]<='9'){
if(x!=3&&y)return 0;
if(a[z]==-1&&IP[i+1]!=':'&&IP[i+1]!='.'&&i+1!=len&&IP[i]=='0')return 0;
if(a[z]==-1)a[z]=0;
a[z]*=10;a[z]+=IP[i]-48;
}
else if(IP[i]=='.'){x++;z++;}
else if(IP[i]==':'){y++;z++;}
else return 0;
}
if(x==3&&y==1&&a[1]<=255&&a[2]<=255&&a[3]<=255&&a[4]<=255&&a[5]<=65535&&a[1]>=0&&a[2]>=0&&a[3]>=0&&a[4]>=0&&a[5]>=0&&a[6]==-1&&a[7]==-1&&a[8]==-1&&a[9]==-1)return 1;
else return 0;
}
bool cz(int x,string y){
for(int i=1;i<=x;i++){
if(y==b[i]){if(ch[0]=='C'&&ch[1]=='l'&&ch[2]=='i'&&ch[3]=='e'&&ch[4]=='n'&&ch[5]=='t')cout<<c[i]<<endl;return 1;}
}
return 0;
}
int main(){
int t,sum=0;
cin>>t;
string a;
for(int i=1;i<=t;i++){
cin>>ch;
cin>>a;
if(ch[0]=='S'&&ch[1]=='e'&&ch[2]=='r'&&ch[3]=='v'&&ch[4]=='e'&&ch[5]=='r'){
if(pd(a)){
if(cz(sum,a)){cout<<"FAIL"<<endl;continue;}
b[++sum]=a;
c[sum]=i;
cout<<"OK"<<endl;
}
else cout<<"ERR"<<endl;
}
else{
if(pd(a)){
if(cz(sum,a))continue;
cout<<"FAIL"<<endl;
}
else cout<<"ERR"<<endl;
}
}
return 0;
}