#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

struct buil{
	int n;
	string b;
	double x, y;
	void next(void){
		cin >> b >> x >> y;
		n = 0;
		int i; rep(i, b.size())n = n * 10 + b[i] - '0';
		return;
	}
};

bool nsort(buil qwe, buil rty){ return qwe.n < rty.n; }
buil B[100];
string G[100][100];
string ma = "#";

int main(void){
	int i, j, k, n, m;
	rep(i, 10)ma += ma;
	for(;;){
		scanf("%d", &n);
		if(!n)break;
		rep(i, n)rep(j, n)G[i][j] = ma;

		rep(i, n)B[i].next();
		sort(B, B + n, nsort);

		rep(i, n)rep(j, n){
			double tmp = (B[i].x - B[j].x) * (B[i].x - B[j].x) + (B[i].y - B[j].y) * (B[i].y - B[j].y);
			if(tmp <= 2500.0)G[i][j] = B[i].b;
		}
		rep(k, n)rep(i, n)rep(j, n)if(G[i][j].size() > G[i][k].size() + G[k][j].size())G[i][j] = G[i][k] + " " + G[k][j];

		scanf("%d", &m);
		for(;m--;){
			scanf("%d %d", &i, &j);
			if(G[i - 1][j - 1] != ma)cout << G[i - 1][j - 1] << " " << B[j - 1].b << endl;
			else puts("NA");
		}
	}
	
	return 0;
}