#include<bits/stdc++.h>
using namespace std;

const int EPS = 1e-6;

struct Building{
	double x,y;
}

struct Edge{
	int to;
	double dist;
	Edge(){}
	Edge(int to_c, double dist_c){
		to = to_c; dist = dist_c;
	}
};

struct Data{
	int n, cost;
	Data(){}
	Data(int n_c, int cost_c){
		n = n_c; cost = cost_c;
	}
	bool operator
}

double GetDistnace(Building b1, Building b2){
	int dx = b1.x - b2.x, dy = b1.y - b2.y;
	return sqrt(dx*dx + dy*dy);
}

vector<Edge> e[1000];

int main(){
	Building b[1000] = {};
	int N, M;
	cin >> N;
	for(int i = 0; i < N; i++){
		int indx;
		cin >> indx; indx--;
		cin >> b[indx].x >> b[indx].y;
	}
	for(int i = 0; i < N; i++){
		if(b[i].x == 0) continue;
		for(int j = 0; j < N; j++){
			if(i == j || b[j].x == 0) continue;
			double dist = GetDistance(b[i], b[j]);
			if(dist <= 50) e[i].push( Edge(j, dist) );
		}
	}
	
	cin >> M;
	for(int i = 0; i < M; i++){
		int s,g;
		cin >> s >> g; s--; g--;
		
		priority_queue<Data> pq;
		Data fpq;
		pq.push( Data(s, 0) );
		double memo[1000];
		fill_n(memo, 1000, 100000);
		while( !pq.empty() ){
			fpq = pq.top();
			if(fpq.n == g) break;
			if(memo[fpq.n] <= 10000) continue;
			for(int j = 0; j < e[fpq.n].size(); j++){
				pq.push( Data( e[fpq.n][j].to, fpq.cost + e[fpq.n][j].dist ) );
			}
		}
		vector<int> ans;
		for(int j = g; j != s;){
			for(int k = 0; k < 1000; k++){
				if( abs( memo[k] + e[j][k].dist - memo[j] ) < EPS ){
					j = k; break;
				}
			}
		}
	}
	
	return 0;
}