public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		init(101);
		while ((line = in.readLine()) != null && line.length() != 0) {
			String[] d = line.trim().split(",");
			union(d[0], d[1], Integer.parseInt(d[3]), d[2]);
		}
		floyd();
		while ((line = in.readLine()) != null && line.length() != 0) {
			String[] d = line.trim().split(",");
			int s = nameToId.get(d[0]), t = nameToId.get(d[1]);
			ArrayList<Route> path = getPath(s, t);
			out.append("\n\nFrom                 To                   Route      Miles\n");
			out.append("-------------------- -------------------- ---------- -----\n");
			for (Route route : path)
				out.append(route + "\n");
			out.append("                                                     -----\n");
			out.append("                                          Total      ");
			out.append(String.format("% 5d", dis[s][t]) + "\n");
		}
		System.out.print(out);
	}