#include<bits/stdc++.h>
using namespace std;
long long a=-1,b=-1,c=-1,d=-1,e=-1;
int n;
char op[100],ad[100],yee[100];
map<string,int> yeewu;
bool flag=0;
void check(char x[])
{
flag=0;
sscanf(x,"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&e);
sprintf(yee,"%lld.%lld.%lld.%lld:%lld",a,b,c,d,e);
for(int i=0;i<strlen(x);i++)
{
if(x[i]!=yee[i])
{
flag=1;
return;
}
}
if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535)
{
flag=1;
return;
}
return;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>op>>ad;
string t(ad);
check(ad);
if(op[0]=='S')
{
if(flag==1)
{
cout<<"ERR"<<endl;
continue;
}
if(yeewu.count(t)==1)
{
cout<<"FAIL"<<endl;
continue;
}
if(yeewu.count(t)==0)
{
cout<<"OK"<<endl;
yeewu[t]=i;
continue;
}
}
if(op[0]=='C')
{
if(flag==1)
{
cout<<"ERR"<<endl;
continue;
}
if(yeewu.count(t)==1)
{
cout<<yeewu[ad]<<endl;
continue;
}
if(yeewu.count(t)==0)
{
cout<<"FAIL"<<endl;
continue;
}
}
}
return 0;
}