#include<bits/stdc++.h>
using namespace std;
int n;
map<string,int> mp;
struct Internet{
int node;
bool law=true;
}net[1005];
bool ok(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)
return false;
if(b<0||b>255)
return false;
if(c<0||c>255)
return false;
if(d<0||d>255)
return false;
if(e<0||e>65535)
return false;
char ss[35];
sprintf(ss,"%d.%d.%d.%d:%d",a,b,c,d,e);
for(int i=0;i<strlen(s);i++)
if(ss[i]!=s[i])
return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
{
string ad;
char op[30];
cin>>ad>>op;
if(ok(op)==false)
cout<<"ERR"<<endl;
else
{
if(ad[0]=='S')
{
if(mp[op]>0)
cout<<"FAIL"<<endl;
else
mp[op]=i,cout<<"OK"<<endl;
}
else
{
if(ad[0]=='C')
{
if(mp[op]==0)
cout<<"FAIL"<<endl;
else
cout<<mp[op]<<endl;
}
}
}
}
return 0;
}