Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"math"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dd := make([][]int, 1000)
	for i := range dd {
		dd[i] = make([]int, 1000)
	}
	num := make([]int,1000)
	inv := make([]int, 1001)
	x := make([]int, 1000)
	y := make([]int, 1000)
	vv := make([]int, 1000)
	nowt := make([]float64, 1000)
	rev := make([]int, 1000)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf1 := strings.Split(scanner.Text(), " ")
			num[i], _ = strconv.Atoi(buf1[0])
			x[i], _ = strconv.Atoi(buf1[1])
			y[i], _ = strconv.Atoi(buf1[2])
			inv[num[i]] = i
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				dd[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])
			}
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf2 := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(buf2[0])
			d, _ := strconv.Atoi(buf2[1])
			c = inv[c]
			d = inv[d]
			for j := 0; j < n; j++ {
				vv[j] = 0
				nowt[j]=999999999
				rev[j]=-1
			}
			nowt[c]=0
			for j := 0; j < n; j++ {
				M := 99999999
				at := 0
				for k := 0; k < n; k++ {
					if vv[k] == 0 && float64(M) > nowt[k] {
						M=int(nowt[k])
						at = k
					}
				}
				if M > 90000000 {
					break
				}
				vv[at]=1
				for k := 0; k < n; k++ {
					if vv[k] == 0 && dd[at][k]<=2500&&nowt[k]>nowt[at]+math.Sqrt(float64(dd[at][k])) {
						nowt[k]=nowt[at]+math.Sqrt(float64(dd[at][k]))
						rev[k] = at
					}
				}
			}
			if vv[d] == 0 {
				fmt.Println("NA")
			} else {
				stack := make([]int, 0)
				V := d
				for V != c {
					stack = append(stack, V)
					V = rev[V]
				}
				fmt.Print(num[c])
				for len(stack) > 0 {
					fmt.Printf(" %d", num[stack[len(stack)-1]])
					stack = stack[:len(stack)-1]
				}
				fmt.Println()
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef pair< double , int > P;
typedef pair< int , P > Pii;
#define reps(i,b,n) for(int i = b ; i < n ; ++i )
#define rep(i,n) reps(i,0,n)
#define INF 10000000
#define fr first
#define sc second
#define EPS (1e-10)
double getdis(int x1,int y1,int x2,int y2){return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));}

int n,s,g;
double d[5001],dis;
int prev[5001];
struct edge{
  int to;
  double cost;
  edge(){}
  edge(int to,double cost):to(to),cost(cost){};
};
vector< vector< edge > > info;
vector<int> dijkstra(){
  vector<int> ans;
  fill_n(d,5001,INF),fill_n(prev,5001,-1);
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0.0,s));
  d[s] = 0.0;
  while(!que.empty()){
    P p = que.top();
    que.pop();
    double dis = p.fr;
    int now = p.sc;
    if(dis > d[now]) continue;
    if(now == g){
      ans.push_back(g);
      int furuwara = g, hayashiya;
      while(furuwara != s){
        furuwara = prev[furuwara];
        ans.push_back(furuwara);
      }
      break;
    }
    rep(i,info[now].size()){
      edge e = info[now][i];
      if(d[now] + e.cost < d[e.to]){
        d[e.to] = d[now] + e.cost;
        que.push(P(d[e.to],e.to));
        prev[e.to] = now;
      }
    }
  }
  return ans;
}
int main(){
  while(cin >> n , n){
    int id[n],x[n],y[n],m;
    rep(i,n) cin >> id[i] >> x[i] >> y[i];
    info.resize(n + 1);
    rep(i,n) rep(j,n){
      if((dis = getdis(x[i],y[i],x[j],y[j])) <= 50.0){
        info[id[i]].push_back(edge(id[j],dis));
      }
    }
    cin >> m;
    while(m--){
      cin >> s >> g;
      vector<int> ans = dijkstra();
      if(ans.empty()) cout << "NA";
      else rep(i,ans.size()) cout << ( i ? " " : "" ) << ans[ans.size()-1-i];
      cout << endl;
    }
    info.clear();
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}


int id[1010]={};
int from[1010]={};
int x[1010];
int y[1010];
int prev[1010];
int done[1010];

struct NODE{
	int to;
	double cost;
	int prev;
	NODE(int to,double cost,int prev) : to(to) ,cost(cost) , prev(prev) {}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++){
			cin >> id[i] >> x[i] >> y[i];
			from[id[i]] = i;
		}
		int m;
		cin >> m;
		for(int xx = 0 ; xx < m ; xx++){
			int s,g;
			cin >> s >> g;
			s = from[s];
			g = from[g];
			priority_queue<NODE> Q;
			Q.push(NODE(s,0,-1));
			memset(done,0,sizeof(done));
			while(Q.size()){
				NODE q = Q.top(); Q.pop();
				if( done[q.to]++ ) continue;
				else prev[q.to] = q.prev;
				if( q.to == g ){
					vector<int> r;
					r.push_back(q.to);
					q.to = prev[q.to];
					while(q.to != -1 ){
						r.push_back(q.to);
						q.to = prev[q.to];
					}
					for(int i = r.size() -1 ; i >= 0 ; i--)
						cout << id[r[i]] << (i?" ":"\n");
					goto exit;
				}
				for(int i = 0 ; i < n ; i++){
					if( (x[q.to]-x[i])*(x[q.to]-x[i])+(y[q.to]-y[i])*(y[q.to]-y[i]) > 2500 ) continue;
					Q.push(NODE(i,q.cost+sqrt((x[q.to]-x[i])*(x[q.to]-x[i])+(y[q.to]-y[i])*(y[q.to]-y[i])),q.to));
				}
			}
			cout << "NA" << endl;
			exit:;
			
		}
	}
}