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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

double cost[1024][1024];
int d[1024];
bool used[1024];
int prev[1024];
int V;

void dijkstra(int s){
	fill(d,d+V,INF);
	fill(used,used+V,false);
	fill(prev,prev+V,-1);
	d[s] = 0;
	while(true){
		int v = -1;
		rep(i,V)if(!used[i] && (v == -1 || d[i] < d[v]))v = i;
		if(v == -1)break;
		used[v] = true;
		rep(i,V){
			if(d[i] > d[v] + cost[v][i]){
				d[i] = d[v] + cost[v][i];
				prev[i] = v;
			}
		}
	}
	return ;
}

vector<int> get_path(int t){
	vector<int> path;
	for(; t != -1; t = prev[t])path.push_back(t);
	reverse(path.begin(),path.end());
	return path;
}

int main(){
	int n;
	while(scanf("%d",&n),n){
		rep(i,1000)rep(j,1000)cost[i][j] = INF;
		int num[12800]={0},x[12800]={0},y[12800]={0};
		rep(i,n){
			scanf("%d%d%d",&num[i],&x[i],&y[i]);
			num[i]--;
		}
		rep(i,n){
			reps(j,i+1,n){
				double dis = sqrt(((x[i]-x[j])*(x[i]-x[j]))+((y[i]-y[j])*(y[i]-y[j])));
				cost[i][j] = (dis > 50) ? INF : dis;
				cost[j][i] = (dis > 50) ? INF : dis;
			}
		}
		V = n;
		int m;
		scanf("%d",&m);
		rep(i,m){
			vector<int> ans;
			int from,to;
			scanf("%d%d",&from,&to);
			from--;to--;
			dijkstra(from);
			ans = get_path(to);
			int len = ans.size();
			if(d[to] == INF)puts("NA");
			else{
				rep(i,len-1)printf("%d ",ans[i]+1);
				printf("%d\n",ans[len-1]+1);
			}			
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



struct Edge{
  int src;int dst;double wei;
  Edge(int s=0,int d=0,double w=0):src(s),dst(d),wei(w){}
};

using Graph = vector<vector<Edge>>;

pair<vector<double>,vector<int>> Dij(Graph&g,int s){
    using state = pair<double,int>;//テ」ツつウテ」ツつケテ」ツδ暗」ツ?ョテァツキツ湘・ツ陳古」ツ??」ツ?ゥテ」ツ?禿」ツ?凝」ツつ嘉ィツヲツ凝」ツ?ヲテ」ツ??」ツつ凝」ツ?ョテ」ツ??
    priority_queue<state,vector<state>,greater<state>> pq;
    vector<int> from(g.size());
    vector<double> dis(g.size(),INF);
    dis[s]=0;
    pq.push(state(0,s));
    while(!pq.empty()){
      double d=pq.top().first;
      int v=pq.top().second;
      pq.pop();
      if(dis[v]<d)continue;
      rep(i,g[v].size()){
        Edge &e=g[v][i];
        if(dis[e.dst]>dis[v]+e.wei){
          dis[e.dst]=dis[v]+e.wei;
          pq.push(state(dis[e.dst],e.dst));
          from[e.dst]=v;
        }
      }
    }
    return mp(dis,from);
}

signed main(){
    int n;
    while(cin>>n,n){
    vector<pair<int,pair<int,int>>> B(n);
  //  vector<int> B(n),X(n),Y(n);
  //  rep(i,n)cin>>B[i]>>X[i]>>Y[i];
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      B[i]=mp(a,mp(b,c));
    }
    sort(B.begin(),B.end());
    Graph g(n);
    rep(i,n)rep(j,n){
      if(i==j)continue;
      //double x=abs(X[i]-X[j]);
      //double y=abs(Y[i]-Y[j]);
      double x=abs(B[i].sec.fir-B[j].sec.fir);
      double y=abs(B[j].sec.sec-B[i].sec.sec);

      if(x*x+y*y<=2500.0){
        double dst=pow(x*x+y*y,0.5);
        g[i].emplace_back(i,j,dst);
        g[j].emplace_back(j,i,dst);
      }
    }

    int m;
    cin>>m;
    vector<int> S(m),G(m);
    rep(i,m)cin>>S[i]>>G[i];
    rep(i,m){
      auto ans=Dij(g,S[i]-1);
      //rep(i,n)cout<<ans.fir[i]<<' '<<ans.sec[i]<<endl;
      if(ans.fir[G[i]-1]==INF){
        cout<<"NA"<<endl;
        continue;
      }
      stack<int> path;
      for(int j=G[i]-1;;j=ans.sec[j]){
        path.push(j);
        if(j==S[i]-1)break;
      }
      while(!path.empty()){
        cout<<path.top()+1;
        if(path.size()!=1)cout<<' ';
        path.pop();
      }
      cout<<endl;
    }

  }

  return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

#define NMAX 1000
typedef pair<double, pair<int, int> > P;
int n;
int b[NMAX], x[NMAX], y[NMAX], prev[NMAX], r[NMAX];
bool u[NMAX];
double c[NMAX], d[NMAX][NMAX];

int solve(int s, int g) {
  P p;
  int num, t;
  priority_queue<P> q;
  bool solved = false;

  memset(u, 0, n);
  memset(c, 0, sizeof(double)*n);
  q.push(make_pair(0.0, make_pair(s, -1)));
  while (!q.empty()) {
    p = q.top();
    q.pop();
    t = p.second.first;
    if (u[t]) continue;
    u[t] = true;
    prev[p.second.first] = p.second.second;
    if (t == g) {
      solved = true;
      break;
    }
    for (int i=0; i<n; i++) {
      if (u[i] || d[t][i] > 50.) continue;
      q.push(make_pair(p.first - d[t][i], make_pair(i, t)));
    }
  }

  if (solved) {
    num = 0;
    t = g;
    while (t!=-1) {
      r[num++] = t;
      t = prev[t];
    }
    reverse(r, r+num);
  }
  return solved ? num : -1;
}

int main() {
  int m, s, g, t;
  map<int,int> id;
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      scanf("%d %d %d", &b[i], &x[i], &y[i]);
    }
    id.clear();
    for (int i=0; i<n; i++) {
      id.insert(make_pair(b[i], i));
    }
    for (int i=0; i<n; i++) {
      for (int j=i; j<n; j++) {
        d[i][j] = d[j][i] = sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
      }
    }
    scanf("%d", &m);
    for (int i=0; i<m; i++) {
      scanf("%d %d", &s, &g);
      t = solve(id[s], id[g]);
      if (t == -1) {
        printf("NA\n");
      } else {
        for (int j=0; j<t; j++) {
          if (j) printf(" ");
          printf("%d", b[r[j]]);
        }
        puts("");
      }
    }
  }
  return 0;
}