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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;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 INF 1<<30

typedef int 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;

void dijkstra(const Graph &g, int s,
                  vector<Weight> &dist, vector<int> &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"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

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


typedef complex<double> P;

int main() {
  int n ;
  while(cin>>n,n) {
    vector<P> v;
    Graph g(n);
    REP(i,n) {
      int b,x,y;
      cin >> b >> x >> y;
      P a = P(x,y);
      REP(j,v.size()) {
        if (abs(a-v[j]) <= 50) {
          g[i].push_back(Edge(i,j,abs(a-v[j])));
          g[j].push_back(Edge(j,i,abs(a-v[j])));
        }
      }
      v.push_back(a);
    }
    int m;
    cin >> m;
    while(m--) {
      int s,t;
      cin >> s >> t;
      vector<int> dist, prev;
      dijkstra(g,s-1,dist,prev);
      if (dist[t-1] == INF) {
        cout << "NA" << endl;
      } else {
        vector<int> path = buildPath(prev,t-1);
        REP(i,path.size()) {
          if (i) cout << " ";
          cout << path[i]+1;
        }
        cout << endl;
      }
    }
    
  }
}

C++: #include <bits/stdc++.h>
#define INF 1000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
double G[101][101];

void dijkstra(int s,int g){
  int cost[101]={};
  memset(cost,-1,sizeof(cost));
  cost[s]=0;
  int from[101]={};
  queue<int> Q;
  Q.push(s);
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    
    for(int i=0;i<n;i++){
      if(G[pos][i]==0||cost[i]!=-1)continue;
      Q.push(i);
      cost[i]=cost[pos]+1;
      from[i]=pos;
    }
  }
  
  vector<int> res;
  res.push_back(g);
  int pos=g;
  while(pos!=s){
    pos=from[pos];
    res.push_back(pos);
  }

  for(int i=0;i<res.size();i++){
    if(i) cout<<" ";
    cout<<res[res.size()-1-i]+1;
  }
  cout<<endl;
}


int main(){
  while(cin>>n,n){
    double x[101],y[101];
    for(int i=0;i<n;i++){
      int b;
      cin>>b;
      cin>>x[b-1]>>y[b-1];
    }
    
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	ll X=(x[i]-x[j]);
	ll Y=(y[i]-y[j]);
	ll dis=X*X+Y*Y;
	G[i][j]=G[j][i]=(dis<=50*50);
      }

    int m;
    cin>>m;
    while(m--){
      int s,g;
      cin>>s>>g;
      dijkstra(s-1,g-1);
    }
  }
  return 0;
}