#include <bits/stdc++.h>
using namespace std;
const long long N=1e5+5;
string op,ad,a[N];
long long t,n=1,s=1;
bool check(string x)
{
int a[6],num=1,sum=0,aum=0;
for (int i=1;i<=strlen(x);i++)
{
if (x>='0'&&x<='9')
a[num]+=x-'0';
else
{
num++;
if (sum!=3&&aum==1)
return false;
if (x=='.')
sum++;
if (x==':')
aum++;
}
}
if (sum!=3||ame!=1||num!=5)
return false;
for (int i=1;i<=4;i++)
if (a[i]>255||a[i]<0)
return false;
if (a[5]>65535||a[5]<0)
return false;
return true;
}
bool pd(string x)
{
for (int i=1;i<=n;i++)
if (a[x]==a[n])
return false;
return true;
}
bool pde(string x)
{
for (int i=1;i<=n;i++)
if (a[x]==a[n])
return true;
return false;
}
int main()
{
cin>>t;
while (t--)
{
cin>>op>>ad;
if (op=="Server")
{
if (check(ad)&&pd(ad))
{
a[n]=ad;
cout<<"OK";
n++;
}
else if (check(ad))
cout<<"FAIL";
else
cout<<"ERR";
}
if (op=="Client")
{
if (check(ad)&&pde(ad))
{
cout<<s;
s++;
}
else if (check(ad))
cout<<"FAIL";
else
cout<<"ERR";
}
}
return 0;
}