#include<cstdio>
#include <iostream>
#include <sstream>
#include <cstring>
using namespace std;
bool flag(char s[])
{
long long a,b,c,d,e;
sscanf(s,"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&e);
if(a>=0&&a<=255&&b>=0&&b<=255&&c>=0&&c<=255&&d>=0&&d<=255&&e>=0&&e<=65535)
{
stringstream f;
f<<a<<"."<<b<<"."<<c<<"."<<d<<":"<<e;
return f.str()==s;
}
return false;
}
bool compare(char a[],char c[])
{
for(int i=1;i<=strlen(a);i++)
if(a[i]!=c[i])
return false;
return true;
}
char a[1022][30];
string type[1022];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>type[i]>>a[i];
if(flag(a[i]))
{
if(type[i][0]=='S')
{
bool f=true;
for(int j=1;j<=i-1;j++)
{
if(type[j][0]=='S'&&compare(a[i],a[j]))
{
f=false;
break;
}
}
if(f) cout<<"OK\n";
else cout<<"FAIL\n";
}
else
{
bool f=false;
for(int j=1;j<=i-1;j++)
{
if(type[j][0]=='S'&&compare(a[i],a[j]))
{
cout<<j<<endl;
f=true;
break;
}
}
if(!f) cout<<"FAIL\n";
}
}
else cout<<"ERR\n";
}
}