#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct gaga{
int a,b,c,d,e,istrue;
string SorC;
gaga(){istrue=1;a=b=c=d=e=-1;}
}cpt[1001];
int n,i,j,a,b,c,d,e,zt[1001],charn[2]={0,0};
char arp[4];
string ip;
int main()
{
freopen("text.in","r",stdin);
freopen("text.out","w",stdout);
cin >> n;
for(i=0;i<n;i++)
{
cin >> cpt[i].SorC;
cin >> ip;
for(j=0;j<ip.lengh();j++)
{
if(ip[j]=='.') charn[0]++;
else if(ip[j]==':') charn[1]++:
else if(ip[j]>=48&&ip[j]<=57)
{
}
}
if()
if(charn[0]==3&&charn[1]==1&&
cpt[i].a<=256&&cpt[i].b<=256&&cpt[i].c<=256&&cpt[i].d<=256&&cpt[i].e<=65535&&
cpt[i].a>=0&&cpt[i].b>=0&&cpt[i].c>=0&&cpt[i].d>=0&&cpt[i].e>=0)
{
if(cpt[i].SorC=="Server")
{
zt[i]=-2;
for(j=0;j<i;j++)
if(cpt[j].istrue&&cpt[j].SorC=="Server"&&cpt[i].a==cpt[j].a&&cpt[i].b==cpt[j].b&&cpt[i].c==cpt[j].c&&cpt[i].d==cpt[j].d&&cpt[i].e==cpt[j].e)
{zt[i]=-1;cpt[i].istrue=0;break;}
}
else
{
zt[i]=-1;
for(j=i-1;j>=0;j--)
{
if(cpt[j].istrue&&cpt[j].SorC=="Server"&&cpt[i].a==cpt[j].a&&cpt[i].b==cpt[j].b&&cpt[i].c==cpt[j].c&&cpt[i].d==cpt[j].d&&cpt[i].e==cpt[j].e)
{zt[i]=j+1;break;}
}
}
}
else{cpt[i].istrue=0;zt[i]=-3;}
}
for(i=0;i<n;i++)
{
if(zt[i]==-1) cout <<"FAIL\n";
else if(zt[i]==-2) cout <<"OK\n";
else if(zt[i]==-3) cout <<"EER\n";
else cout << zt[i]<<"\n";
}
fclose(stdin);
fclose(stdout);
return 0;
}