#include<bits/stdc++.h>
using namespace std;
int n=0;
string type[1001];
string node[1001];
bool state[1001];
bool compare(string a,string b){
int lena=a.length();
int lenb=b.length();
if(lena!=lenb){
return false;
}
for(int i=1;i<=lena;i++){
if(a[i]!=b[i]){
return false;
}
}
return true;
}
bool exturn(string s){
long long a,b,c,d,e;
if(sscanf(s.c_str(),"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&e)!=5)return false;
if(a<0||a>255)return 0;
if(b<0||b>255)return 0;
if(c<0||c>255)return 0;
if(d<0||d>255)return 0;
if(e<0||e>65535)return 0;
char s2[101]={};
sprintf(s2,"%lld.%lld.%lld.%lld:%lld",a,b,c,d,e);
int len=strlen(s2);
bool ok=0;
for(int i=0;i<len;i++){
if(s[i]==s2[i]) ok=1;
else{
ok=0;
break;
}
}
return ok;
}
int main(){
int n=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>type[i]>>node[i];
if(!exturn(node[i])){
cout<<"ERR"<<endl;
}else{
if(type[i][0]=='S'){
bool ok=false;
if(i==1){
cout<<"OK"<<endl;
continue;
}
for(int j=1;j<i;j++){
if(compare(node[i],node[j])&&type[j][0]=='C'){
ok=true;
cout<<"OK"<<endl;
break;
}else{
ok=false;
}
}
if(ok==false){
cout<<"FAIL"<<endl;
}
}else{
if(i==1){
cout<<"FAIL"<<endl;
continue;
}
bool ok=false;
for(int j=1;j<i;j++){
if(compare(node[i],node[j])&&type[j][0]=='S'){
ok=true;
cout<<j<<endl;
break;
}else{
ok=false;
}
}
if(ok==false){
cout<<"FAIL"<<endl;
}
}
}
}
return 0;
}