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<queue>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef struct{
  int x;
  int y;
}BILL;
typedef pair<int,int> P;
const int INF = (1<<20);
const int MAX = 1001;
BILL bill[MAX];
int pre[MAX],node[MAX];
int n,m;
vector<int> IN;

void init(){
  fill(pre,pre+MAX, -1);
  fill(node,node+MAX, INF);
}


double Getd(BILL a, BILL b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void solve(int from, int to){
  init();
  node[from] = 0;
  priority_queue<P,vector<P>, greater<P> > Q;
  Q.push(P(node[from],from));
  //Q(distance,name)
  while(!Q.empty()){
    P now = Q.top(); Q.pop();
    if(now.first > node[now.second]) continue;
    for(int i = 0; i < IN.size(); i++){
      int next = IN[i];
      if(Getd(bill[now.second],bill[next]) <= 50 && Getd(bill[now.second],bill[next]) > 0)
	if(node[next] > now.first+Getd(bill[now.second],bill[next])){
	  node[next] = now.first+Getd(bill[now.second],bill[next]);
	  Q.push(P(node[next],next));
	  pre[next] = now.second;
	}
    }
  }

  vector<int> V;
  int prec = to;
  if(node[to] == INF) cout << "NA";
  else {
    V.push_back(to);
    while(pre[prec] != -1){
      V.push_back(pre[prec]);
      prec = pre[prec];
    }
  }
  reverse(V.begin(),V.end());
  for(int i = 0; i < V.size(); i++){
    if(i) cout << " ";
    cout << V[i];
  }
  cout << endl;
}

int main(){
  while(cin >> n && n){
    IN.clear();
    for(int i = 0; i < n; i++){
      int num;
      cin >> num;
      cin >> bill[num].x >> bill[num].y;
      IN.push_back(num);
    }
    cin >> m;
    for(int i = 0; i < m; i++){
      int f,t;
      cin >> f >> t;
      solve(f,t);
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
#define INF 1e10
#define EPS 1e-10
#define EQ(a,b) (fabs((a)-(b))<EPS)

double dist[1000][1000];
int id[1000],x[1000],y[1000];

double Distance(int i,int j){
	return sqrt((double)(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}


int main(){
	int n;
	while(cin>>n&&n){
		for(int i=0;i<n;i++)cin>>id[i]>>x[i]>>y[i];
		for(int i=0;i<n;i++)for(int j=0;j<n;j++){
			double d=Distance(i,j);
			dist[i][j]=(d<50+EPS?d:INF);
		}
		for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
			dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			int s,g;
			cin>>s>>g;
			for(int i=0;i<n;i++){
				if(s==id[i]){
					s=i;
					break;
				}
			}
			for(int i=0;i<n;i++){
				if(g==id[i]){
					g=i;
					break;
				}
			}
			if(dist[s][g]==INF){
				cout<<"NA\n";
				continue;
			}
			stack<int> st;
			int v=g;
			while(v!=s){
				for(int i=0;i<n;i++){
					if(i==v)continue;
					double d=Distance(i,v);
					if(d<50+EPS && EQ(dist[s][v],dist[s][i]+d)){
						st.push(v);
						v=i;
						break;
					}
				}
			}
			cout<<id[s];
			while(!st.empty()){
				cout<<' '<<id[st.top()];
				st.pop();
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int to; T cost;
    edge(int to, T cost) : to(to), cost(cost) {}
};


template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> id(n), xs(n), ys(n);
        map<int, int> A, Ainv;
        for (int i = 0; i < n; ++i) {
            scanf("%d %d %d", &id[i], &xs[i], &ys[i]);
            A[i] = id[i];
            Ainv[id[i]] = i;
        }
        vector<vector<edge<double>>> G(n);
        for (int i = 0; i < n; ++i) {
            for (int j = i+1; j < n; ++j) {
                if((xs[i]-xs[j])*(xs[i]-xs[j])+(ys[i]-ys[j])*(ys[i]-ys[j]) <= 2500){
                    G[i].emplace_back(j, hypot(xs[i]-xs[j], ys[i]-ys[j]));
                    G[j].emplace_back(i, hypot(xs[i]-xs[j], ys[i]-ys[j]));
                }
            }
        }
        int m;
        cin >> m;
        while(m--){
            int s, g;
            cin >> s >> g;
            vector<double> dist(n, 1e18);
            vector<int> prev(n);
            GPQ<pair<double, int>> Q;
            s = Ainv[s]; g = Ainv[g];
            Q.emplace(0, s);
            while(!Q.empty()){
                double cost; int i;
                tie(cost, i) = Q.top(); Q.pop();
                if(dist[i] < cost) continue;
                for (auto &&e : G[i]) {
                    auto cost2 = cost + e.cost;
                    if(dist[e.to] <= cost2) continue;
                    dist[e.to] = cost2;
                    Q.emplace(dist[e.to], e.to);
                    prev[e.to] = i;
                }
            }
            if(dist[g] > 1e16) {
                puts("NA");
                continue;
            }
            vector<int> ans;
            while(g != s){
                ans.emplace_back(g);
                g = prev[g];
            }
            ans.emplace_back(s);
            reverse(ans.begin(),ans.end());
            for (int i = 0; i < ans.size(); ++i) {
                printf(i ? " %d" : "%d", A[ans[i]]);
            }
            puts("");
        }
    }
    return 0;
}