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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define dis(a,b) (a)*(a)+(b)*(b)
using namespace std;
void f(vector<int> v,vector<int> &x,int d[][1001],int p[],int c,int e,double s){
  int i;
  vector<int> w=v;
  if(c==e){
    if(p[c]==-1||p[c]>s){
      w.push_back(c);
      x.reserve(w.size());
      x=w;
      p[c]=s;
    }
  }else if(p[c]==-1||p[c]>s){
    w.push_back(c);
    p[c]=s;
    for(i=1;i<1001;i++){
      if(d[c][i]&&d[c][i]<=2500)
	f(w,x,d,p,i,e,s+sqrt(d[c][i]));
    }
  }
  return;
}
int main(){
  int i,j;
  int m,n;
  int p[1001],x[1001],y[1001],d[1001][1001];
  int *b,*e,*g;
  vector<int> v,w;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(d,0,sizeof(d));
    g=new int[n];
    for(i=0;i<n;i++){
      cin>>g[i];
      cin>>x[g[i]]>>y[g[i]];
      for(j=0;j<i;j++){
	d[g[i]][g[j]]=dis(x[g[i]]-x[g[j]],y[g[i]]-y[g[j]]);
	d[g[j]][g[i]]=d[g[i]][g[j]];
      }
    }
    delete[]g;
    cin>>m;
    b=new int[m];
    e=new int[m];
    for(i=0;i<m;i++)
      cin>>b[i]>>e[i];
    for(i=0;i<m;i++){
      v.clear();
      w.clear();
      memset(p,-1,sizeof(p));
      f(v,w,d,p,b[i],e[i],0.0);
      if(w.empty())
	cout<<"NA"<<endl;
      else{
	for(j=0;w.size()-1;j++)
	  cout<<w[j]<<" ";
	cout<<w[j]<<endl;
      }
    }
    delete[]b;
    delete[]e;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

typedef double Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src_, int dst_, Weight weight_) :
        src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

double const inf = 1e100;
void dijk(Graph const&g, int s, vector<Weight> &dist, vi &prev) {
    int n = g.size();
    dist.assign(n, inf); dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Edge> q; // "e < f" <=> "e.weight > f.weight"
    q.push(Edge(-2, s, 0));
    while(q.size()) {
        Edge e = q.top();
        q.pop();
        if (prev[e.dst] != -1) continue;
        prev[e.dst] = e.src;
        for(auto f : g[e.dst]) {
            if (dist[f.dst] > e.weight+f.weight) {
                if(f.weight > 50) continue;
                dist[f.dst] = e.weight+f.weight;
                q.push(Edge(f.src, f.dst, e.weight+f.weight));
            }
        }
    }
}

vi buildPath(vi const& prev, int t) {
    vi path;
    for (int u = t; u >= 0; u = prev[u])
        path.push_back(u);
    reverse(all(path));
    return path;
}


int main(){
    int n;
    while(cin >> n && n){
        map<int,pair<int,int>> m;
        rep(i,n){
            int b;
            double x,y;
            cin >> b >> x >> y;
            m[b] = mp(x,y);
        }
        Graph g(m.rbegin()->first + 10);
        rep(i,g.size())rep(j,g.size()){
            double dx = m[i].first - m[j].first;
            double dy = m[i].second - m[j].second;
            double dist = sqrt(dx*dx + dy*dy);
            g[i].eb(i,j,dist);
        }
        int t;
        cin >> t;
        rep(i,t){
            int s1,g1;
            cin >> s1 >> g1;
            dump(s1,g1);
            vector<Weight> dist;
            vector<int> prev;
            dijk(g,s1,dist,prev);
            if(dist[g1]==inf){
                cout << "NA" << endl;
            } else {
                vi ans = buildPath(prev,g1);
                rep(i,ans.size()){
                    cout << ans[i];
                    cout << (i+1==(int)ans.size() ? "\n" : " ");
                }
            }
        }
    }
}