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<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const double EPS = 1e-8;
int main(){
	int n,m,s,g,t;
	while(cin>>n,n){
		double adj[n][n]; rep(i,n)rep(j,n)adj[i][j]=60;
		int x[n],y[n];
		rep(i,n){
			cin>>t>>x[i]>>y[i];
			if(t<1||t>n)return 1;
		}
		rep(i,n)rep(j,i)adj[i][j]=adj[j][i]=hypot(x[i]-x[j],y[i]-y[j]);
		
		cin>>m;
		while(m--){
			cin>>s>>g,s--,g--;
			double cost[n]; rep(i,n)cost[i]=99999999; cost[s]=0;
			vector<vector<int> > path(n); path[s].push_back(s);
			
			vector<int> frontier,next; frontier.reserve(n),next.reserve(n);
			frontier.push_back(s);
			for(;cost[g]==99999999&&!frontier.empty();){
				next.clear();
				rep(i,frontier.size()){
					rep(j,n){
						t=frontier[i];
						if(adj[t][j]<50+EPS&&cost[j]+EPS>cost[t]+adj[t][j]){
							cost[j]=cost[t]+adj[t][j];
							path[j]=path[t],path[j].push_back(j);
							next.push_back(j);
						}
					}
				}
				frontier=next;
			}
			if(cost[g]==99999999)cout<<"NA"<<endl;
			else rep(i,path[g].size())
			cout<<path[g][i]+1<<(i==path[g].size()-1?"\n":" ");
		}
	}
	return 0;
}

C++: //45
#include<iostream>
#include<cmath>

#define S(X) ((X)*(X))

using namespace std;

int main(){
  int px[1001],py[1001],bn[1001],ni[1001];
  for(int n;cin>>n,n;){
    for(int i=0;i<n;i++){
      cin>>bn[i]>>px[i]>>py[i];
      ni[bn[i]]=i;
    }
    int m;
    cin>>m;
    while(m--){
      int s,g;
      cin>>s>>g;
      int p[1001];
      double d[1001];
      fill(p,p+1001,-1);
      fill(d,d+1001,1<<29);
      bool u[1001]={};
      d[ni[g]]=0;
      for(;;){
	int x,md=1<<29;
	for(int j=0;j<n;j++){
	  if(!u[j]&&md>d[j]){
	    x=j;
	    md=d[j];
	  }
	}
	if(md==1<<29)break;
	u[x]=true;
	for(int i=0;i<n;i++){
	  double ds=sqrt(S(px[x]-px[i])+S(py[x]-py[i]));
	  if(ds<=50&&d[x]+ds<d[i]){
	    d[i]=d[x]+ds;
	    p[i]=x;
	  }
	}
      }
      if(d[ni[s]]==1<<29){
	cout<<"NA"<<endl;
      }else{
	int i=ni[s];
	while(i!=-1){
	  cout<<((i==ni[s])?"":" ")<<bn[i];
	  i=p[i];
	}
	cout<<endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)
#define DBL(x) ((x)*(x))

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  bool minus = false;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  if(c == '-'){
    minus = true;
    c = getchar();
  }
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  if(minus) ret *= -1;
  return ret;
}

double load[1000][1000];
bool memo[1000];
int prev[1000];
int b[1000];
int x[1000];
int y[1000];
int mapping[1001];

int main(){
  int n;
  while(n = getInt()){
    memset(mapping, -1, sizeof(mapping));
    REP(i,n){
      b[i] = getInt();
      x[i] = getInt();
      y[i] = getInt();
      mapping[b[i]] = i;
    }

    REP(i,n) REP(j,n){
      double d = sqrt(DBL(x[i]-x[j]) + DBL(y[i]-y[j]));
      load[i][j] = load[j][i] = (d <= 50 + 1e-10 ? d : 0.0);
    }

    int m = getInt();
    while(m --> 0){
      int s = mapping[getInt()];
      int g = mapping[getInt()];
      memset(memo, 0, sizeof(memo));

      if(s == -1 || g == -1){
        puts("NA");
        continue;
      }

      typedef pair<double,pair<int,int> > data;
      priority_queue<data,vector<data>,greater<data> > q;
      q.push(mp(0.0, mp(s, -1)));

      while(!q.empty()){
        double cost = q.top().f;
        int pos  = q.top().s.f;
        int ppos = q.top().s.s;

        q.pop();

        if(memo[pos]) continue;
        memo[pos] = true;
        prev[pos] = ppos;

        if(pos == g){
          vector<int> ans;
          while(pos != s){
            ans.push_back(pos);
            pos = prev[pos];
          }
          ans.push_back(s);
          for(int i=ans.size()-1; i>=0; i--)
            printf("%d%c",b[ans[i]],i==0?'\n':' ');
          break;
        }

        REP(i,n)
          if(!memo[i] && load[pos][i] != 0.0)
            q.push(mp(cost + load[pos][i], mp(i, pos)));

        if(q.empty()){
          puts("NA");
          break;
        }
      }
    }

  }
  return 0;
}