#include <bits/stdc++.h>
using namespace std;
int n;
string a,b;
map < string,int > m;
bool hefa(string a)
{
string bd="";
if(a[0]=='0' && a[1]!='.')
return false;
int s=0,ans[7]={0},ss=0,t=0;
for(int i=0;i<a.size();i++)
{
if(a[i]!='.' && a[i]!=':')
s=s*10+(a[i]-'0');
else
{
bd+=a[i];
if(a[i+1]=='0' && a[i+2]!='.' && a[i+2]!=':')
return false;
ans[++t]=s;
s=0;
ss++;
}
}
ans[++t]=s;
ss++;
if(ss!=5 || ans[1]>255 || ans[2]>255 || ans[3]>255 || ans[4]>255 || ans[5]>65535 || bd!="...:")
return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>b;
if(!hefa(b))
cout<<"ERR"<<endl;
else
{
if(a=="Server")
{
if(m.count(b)==0)
{
m[b]=i;
cout<<"OK"<<endl;
}
else
cout<<"FAIL"<<endl;
}
else
{
if(m.count(b)==0)
cout<<"FAIL"<<endl;
else
cout<<m[b]<<endl;
}
}
}
return 0;
}