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

using namespace std;

typedef double Weight;
const Weight INF = 1e9;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int f, int t, Weight c) :
        src(f), dst(t), weight(c) {}
};
bool operator<(const Edge &a, const Edge &b) {
    return a.weight != b.weight ? a.weight > b.weight :
        a.src != b.src ? a.src < b.src : a.dst < b.dst;
}
bool operator>(const Edge &a, const Edge &b) { return b < a; }

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m;

struct Point {
    double x, y;
    Point() {}
};

void Dijkstra(const Graph &g, int s,
              vector<Weight> &dist, vector<int> &prev) {
    int n = g.size();

    dist.assign(n, INF);
    prev.assign(n, - 1);

    dist[s] = 0;
    priority_queue<Edge> que;  // e < f <=> e.weight > f.weight

    for (que.push(Edge(-2, s, 0)); !que.empty(); ) {
        Edge e = que.top();  que.pop();
        if (prev[e.dst] != -1)
            continue;

        prev[e.dst] = e.src;
        for (auto f = g[e.dst].begin(); f != g[e.dst].end(); ++f) {
            if (dist[f->dst] > e.weight + f->weight) {
                dist[f->dst] = e.weight + f->weight;
                que.push(Edge(f->src, f->dst, e.weight + f->weight));
            }
        }
    }
}

// 始点から頂点tまでの最短経路を返す
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;
}


int main()
{
    while (cin >> n, n) {
        Graph g(n);
        vector<Weight> dist(n);
        vector<int> prev(n);
        vector<Point> pos(n);

        // Input
        for (int i = 0; i < n; ++i)
            cin >> pos[i].x >> pos[i].x >> pos[i].y;

        // Preprocessing
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j) {
                double d = (pos[i].x - pos[j].x) * (pos[i].x - pos[j].x)
                    + (pos[i].y - pos[j].y) * (pos[i].y - pos[j].y);
                d = sqrt(d);
                if (d < 50 + 1e-8) {
                    g[i].push_back(Edge(i, j, d));
                    g[j].push_back(Edge(j, i, d));
                }
            }

        cin >> m;
        int s, t;
        for (int i = 0; i < m; ++i) {
            cin >> s >> t;
            --s, --t;

            Dijkstra(g, s, dist, prev);
            if (dist[t] >= INF)
                cout << "NA\n";
            else {
                vector<int> path = BuildPath(prev, t);
                for (size_t i = 0; i < path.size() - 1; ++i)
                    cout << path[i] + 1 << " ";
                cout << path[path.size() - 1] + 1 << '\n';
            }
        }

    }

    return 0;
}