#include<iostream>
#include<map>
#include<cstring>
using namespace std;
map<string,int> vis;
bool check(char s[]){
int a=-1,b=-1,c=-1,d=-1,e=-1;
int t=sscanf(s,"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
if(t!=5)return false;
if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)return false;
char ss[105];
sprintf(ss,"%d.%d.%d.%d:%d",a,b,c,d,e);
int len=strlen(ss);
int ok=0;
for(int i=0;i<len;i++)
if(s[i]==ss[i])ok=1;
else return false;
if(ok==1)return true;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
char op[1005],ad[1005];
cin>>op>>ad;
string t(ad);
if(op[0]=='S')
if(!check(ad))cout<<"ERR"<<endl;
else if(vis.count(t)!=0)cout<<"FAIL"<<endl;
else{
cout<<"OK"<<endl;
vis[t]=i;
}
else
if(!check(ad))cout<<"ERR"<<endl;
else if(vis.count(t)==0)cout<<"FAIL"<<endl;
else cout<<vis[ad]<<endl;
}
return 0;
}