#include <bits/stdc++.h>
using namespace std;
string op;
string ip;
struct node {
int a, b, c, d, e;
bool stat;
bool sorc;
} con[1005];
int tpow(int a) {
int aa = 1;
while (a --) aa *= 10;
return aa;
}
int n;
int main() {
freopen("network.in", "r", stdin);
freopen("network.out", "w", stdout);
cin >> n;
for (int round = 1; round <= n; round ++) {
cin >> op >> ip;
int cnt = 0;
int cnt2 = 1;
bool iszero = true;
bool zerofail = false;
for (int i = ip.size() - 1; i >= 0; i --) {
if (ip[i] == ':' || ip[i] == '.') {
if (ip[i] == ':' && cnt2 != 1) {
zerofail = true;
break;
}
if (ip[i] == '.' && cnt2 == 1) {
zerofail = true;
break;
}
if (iszero && cnt != 1) {
zerofail = true;
break;
}
cnt = 0;
cnt2 ++;
continue;
}
if (cnt2 == 1) {
if (ip[i] - '0' == 0) iszero = 1;
else iszero = 0;
con[round].e += (ip[i] - '0') * tpow(cnt);
cnt ++;
}
if (cnt2 == 2) {
if (ip[i] - '0' == 0) iszero = 1;
else iszero = 0;
con[round].d += (ip[i] - '0') * tpow(cnt);
cnt ++;
}
if (cnt2 == 3) {
if (ip[i] - '0' == 0) iszero = 1;
else iszero = 0;
con[round].c += (ip[i] - '0') * tpow(cnt);
cnt ++;
}
if (cnt2 == 4) {
if (ip[i] - '0' == 0) iszero = 1;
else iszero = 0;
con[round].b += (ip[i] - '0') * tpow(cnt);
cnt ++;
}
if (cnt2 == 5) {
if (ip[i] - '0' == 0) iszero = 1;
else iszero = 0;
con[round].a += (ip[i] - '0') * tpow(cnt);
cnt ++;
}
}
if (cnt2 != 5 || zerofail) {
cout << "ERR" << endl;
continue;
}
if (con[round].a > 255 || con[round].b > 255 || con[round].c > 255 || con[round].d > 255 || con[round].e > 65545) {
cout << "ERR" << endl;
continue;
}
con[round].stat = true;
bool found = false;
int foundpos;
bool isserver = false;
for (int i = 1; i < round; i ++) {
if (con[i].a == con[round].a && con[i].b == con[round].b && con[i].c == con[round].c && con[i].d == con[round].d && con[i].e == con[round].e && con[i].stat) {
if (con[i].sorc) {
isserver = true;
foundpos = i;
}
found = true;
}
}
if (op == "Server") {
con[round].sorc = true;
if (found && isserver) {
cout << "FAIL" << endl;
con[round].stat = false;
continue;
}
else {
cout << "OK" << endl;
continue;
}
}
else {
if (found && isserver) {
cout << foundpos << endl;
continue;
}
else {
cout << "FAIL" << endl;
}
}
}
return 0;
}
本蒟蒻写的T3,各位大佬看看能不能A掉 恶臭马蜂不要介意(