#include <bits/stdc++.h>
using namespace std;
int n, x = 1;
map<string, int>a;
string c, b;
bool check(string c, string b) {
long long d = 0, e = 0, f = 0, g = 0, h = 0;
long long no = 0;
char t;
if (sscanf(b.c_str(), "%lld.%lld.%lld.%lld:%lld", &d, &e, &f, &g, &h) != 5) {
return false;
}
if (d < 0 || e < 0 || f < 0 || g < 0 || h < 0 || d > 255 || f > 255 || e > 255 || g > 255 || h > 65535) {
return false;
}
sscanf(b.c_str(), "%lld.%lld.%lld.%lld%c%lld", &no, &no, &no, &no, &t, &no);
if (t != ':') {
return false;
}
return true;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c >> b;
if (c == "Server") {
auto it = a.count(b);
if (it == 0) {
if (check(c, b)) {
a.insert(pair<string, int>(b, x));
x++;
cout << "OK" << endl;
} else {
cout << "ERR" << endl;
}
} else {
cout << "FAIL" << endl;
}
} else {
if (check(c, b)) {
auto it = a.find(b);
auto it2 = a.count(b);
if (it2 != 0) {
cout << it->second << endl;
} else {
cout << "FAIL" << endl;
}
} else {
cout << "ERR" << endl;
}
}
}
return 0;
}
求调