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 <cmath>
#include <queue>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <map>
#include <cstdlib>
#include <ctime>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<double, int> state;

double memo[100];
int pre[100];
int name[100];
double x[100];
double y[100];

map<int, int> nums;

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

int main(){
  int n, m;
  int b;
  int s, g;
  while(cin >> n &&n){
    nums.clear();
    rep(i, n){
      cin >> b >> x[i] >> y[i];
      name[i] = b;
      nums[b] = i;
    }
    cin >> m;
    rep(i, m){
      memset(pre, -1, sizeof(pre));
      fill(memo, memo + 100, 1e10);
      cin >> s >> g;
      memo[nums[s]] = 0;
      priority_queue<state, vector<state>, greater<state> > que;
      que.push(state(0, nums[s]));
      while(!que.empty()){
	state st = que.top();
	que.pop();
	int v = st.second;
	double cost = st.first;
	if(name[v] == g){
	  break;
	}
	if(cost > memo[v]) continue;
	rep(i, n){
	  double d = dis(v, i);
	  if(d > 50.0) continue;
	  if(memo[i] > memo[v] + d){
	    memo[i] = memo[v] + d;
	    pre[i] = v;
	    que.push(state(memo[i], i));
	  }
	}
      }
      if(pre[nums[g]] == -1 && s != g){
	cout << "NA" << endl;
      }else{
	vector<int> res;
	int v = nums[g];
	res.push_back(v);
	while(pre[v] >= 0){
	  v = pre[v];
	  res.push_back(v);
	}
	rep(i, (int)res.size()){
	  if(i != 0) cout << " " ;
	  cout << name[res[res.size() - 1 - i]];
	}
	cout << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;

const int INF = 1<<28;

struct Edge {
    int from, to, cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const Edge &o) const {
        return (cost < o.cost);
    }
    bool operator>(const Edge &o) const {
        return (cost > o.cost);
    }
};
struct State {
    int v;
    int min_cost;
    State(int v, int min_cost) : v(v), min_cost(min_cost) {}
    bool operator<(const State &o) const {
        return (min_cost < o.min_cost);
    }
    bool operator>(const State &o) const {
        return (min_cost > o.min_cost);
    }
};
typedef vector<Edge> Vertex;
struct Graph {
    vector<Vertex> g;

    Graph() {}

    Graph(int vertex_count) : g(vertex_count) {}
    Graph(vector<Vertex> g) : g(g) {}

    inline Vertex& operator[](int index) {
        return g[index];
    }

    inline void add_vertex(Vertex v) {
        g.push_back(v);
    }

    inline void add_edge(int from, int to, double cost) {
        g[from].push_back(Edge(from, to, cost));
    }
    
    void min_path(int s, vector<int>& min_cost, vector<int> &prev_v) {
        min_cost.resize(g.size());
        prev_v.resize(g.size());
        fill(prev_v.begin(), prev_v.end(), -1);
        priority_queue< State, vector<State>, greater<State> > q;
        
        fill(min_cost.begin(), min_cost.end(), INF);

        min_cost[s] = 0;
        q.push(State(s, 0));

        while (!q.empty()) {
            State p = q.top(); q.pop();
            int v = p.v;
            if (min_cost[v] < p.min_cost) continue;
            for (int i = 0; i < g[v].size(); i++) {
                Edge e = g[v][i];
                if (min_cost[e.to] > min_cost[v] + e.cost)  {
                    min_cost[e.to] = min_cost[v] + e.cost;
                    prev_v[e.to] = e.from;
                    q.push(State(e.to, min_cost[e.to]));
                }
            }
        }
    }
};

#define MAX_N 1001

struct Bill {
    int b, x, y;
    double dist(const Bill &o) const {
        double dx = x - o.x;
        double dy = y - o.y;
        return sqrt(dx*dx+dy*dy);
    }
};

int main() {
    int n;
    while (cin >> n, n != 0) {
        Graph g(MAX_N);
        vector<Bill> pos;
        for (int i = 0; i < n; i++) {
            Bill b;
            cin >> b.b >> b.x >> b.y;
            pos.push_back(b);
        }
        for (int i = 0; i < pos.size(); i++) {
            for (int j = 0; j < pos.size(); j++) {
                double d = pos[i].dist(pos[j]);
                if (d <= 50) g.add_edge(pos[i].b, pos[j].b, d);
            }
        }
        int m; cin >> m;
        for (int i = 0; i < m; i++) {
            int s, _g; cin >> s >> _g;
            vector<int> prev_v;
            vector<int> min_cost;
            g.min_path(s, min_cost, prev_v);
            if (min_cost[_g] == INF) cout << "NA" << endl;
            else {
                stack<int> st;
                st.push(_g);
                while (prev_v[_g] != -1) {
                    st.push(prev_v[_g]);
                    _g = prev_v[_g];
                }

                cout << st.top(); st.pop();
                while (!st.empty()) {
                    cout << ' ';
                    cout << st.top();
                    st.pop();
                }
                cout << endl;
            }
        }
    }
    return 0;
}