#include<bits/stdc++.h>
using namespace std;
long long num[15];
int cnt; //已有的服务器个数
pair<string, int> ip[1005]; //服务器地址和编号
inline bool isnum(char ch) { //判断是否是数字
return ch >= '0' && ch <= '9';
}
bool judge(string s) {
memset(num, 0, sizeof(num));
int c1, c2, ind;//c1:'.'个数 c2:':'个数
c1 = c2 = ind = 0;
bool f = 1;
for (int i = 0; i < s.size(); ++i) {
if (isnum(s[i])) {
if (s[i] == '0' && f && isnum(s[i + 1])) return 0; //判断前导0
num[ind] = num[ind] * 10 + s[i] - '0';
f = 0;
continue;
}
if (s[i] == '.') {
++c1;
++ind;
f = 1;
continue;
}
if (s[i] == ':') {
++c2;
++ind;
f = 1;
continue;
}
return 0;
}
if (ind != 4 || c1 != 3 || c2 != 1 || num[0] > 255 || num[1] > 255 || num[2] > 255 || num[3] > 255 || num[4] > 65535) return 0;
return 1;
}
int find(string s) {
for (int i = 0; i < cnt; ++i)
if (s == ip[i].first) return i;
return -1;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int k = 0; k < n; ++k) {
string op, ad;
cin >> op >> ad;
if (judge(ad)) {
if (op == "Server") {
if (find(ad) != -1) cout << "FAIL" << endl;
else {
ip[cnt++] = make_pair(ad, k + 1);
cout << "OK" << endl;
}
} else {
int d = find(ad);
if (d == -1) cout << "FAIL" << endl;
else cout << ip[d].second << endl;
}
} else cout << "ERR" << endl;
}
return 0;
}