#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#define no cout << "KHONG" << endl
#define yes cout << step << endl
using namespace std;
int step = 0;
int n, m;
struct POINT {
double x, y, z;
};
vector<POINT> points;
int compare(POINT a, POINT b) {
if (a.x < b.x) return -1;
else
if (a.x > b.x) return 1;
else
if (a.y < b.y) return -1;
else
if (a.y > b.y) return 1;
else
if (a.z < b.z) return -1;
else
if (a.z > b.z) return 1;
else return 0;
}
void get_info() {
cin >> n;
POINT temp;
for (int i = 0; i < n; i++) {
cin >> temp.x >> temp.y >> temp.z;
points.push_back(temp);
}
}
int BinSearch(vector<POINT> A, POINT a) {
int l = 0, r = n - 1, i;
while (l <= r) {
step++;
i = (r - l) / 2 + l;
if (compare(A[i], a) == 0) return i;
if (compare(A[i], a) == -1) l = i + 1;
if (compare(A[i], a) == 1) r = i - 1;
//cout << "$$ " << l << " - " << r << " | " << i << endl;
}
return -1;
}
void solve() {
step = 0;
POINT temp;
cin >> temp.x >> temp.y >> temp.z;
if (BinSearch(points, temp) == -1) no;
else yes;
}
int main() {
get_info();
cin >> m;
for (int i = 0; i < m; i++) solve();
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}