//* Problem  : G - Globetrotter
//* Contest  : UzhNU Local
//* Origin   : Ulm-1997
//* Type     : Solution
//* Date     : 2008.02.04
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : Floyd + Geo

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define PI 3.141592653589793

struct point{
	double lat, lon;
}b[128];

int n;

char dict[128][32];

char s1[1000], s2[1000];

double a[128][128];

int find(char *s)
{
	for (int i = 0; i < n; i++)
		if (!strcmp(s, dict[i])) return i;
	return -1;
}

double spherical_distance(double p_lat, double p_long, double q_lat, double q_long, double r)
{
	return acos( sin(p_lat) * sin(q_lat) + cos(p_lat) * cos(q_lat) * cos(p_long) * cos(q_long) + cos(p_lat) * cos(q_lat) * sin(p_long) * sin(q_long)) * r;
}


int main()
{
	while (1)
	{
		scanf("%s", dict[n]);// if (dict[n][0] == '#') break;
		if (!strcmp(dict[n], "#")) break;
		scanf("%lf%lf", &b[n].lat, &b[n].lon);
		b[n].lat *= PI / 180.0;
		b[n].lon *= PI / 180.0;
		n++;
	}
	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++)
			a[i][j] = a[j][i] = spherical_distance(b[i].lat, b[i].lon, b[j].lat, b[j].lon, 6378.0);
	while (1)
	{
		scanf("%s%s", s1, s2);// if (s1[0] == '#') break;
		//if (!strcmp(s1, "# #")) break;
		if (s1[0] == '#' && s2[0] == '#') break;
		int k1 = find(s1);
		int k2 = find(s2);
		printf("%s - %s\n", s1, s2);
		if (k1 == -1 || k2 == -1) printf("Unknown\n\n");
			else printf("%.0lf km\n\n", k1 != k2 ? a[k1][k2] : 0);
	}
	return 0;
}