// Arup Guha
// 7/14/2026
// Solution to 1994 UCF HSPT Problem: Nothin' But Net

/*** Note: Pretty sure no one got this in contest. There are so many silly gotcha's
           in this problem. An example is empty paths (requiring a capital Nothin'
		   but net.) But, this is a good problem. I should write a checker since
		   they didn't write one. That will also be really annoying. I ended up
		   hand-checking that this solution passed of their cases since I do a BFS
		   and the judge solution must not (it finds unnecessarily long paths).
***/

import java.util.*;

class edge {
	public int u;
	public int v;
	public int type;

	public edge(int myu, int myv, int myt) {
		u = myu;
		v = myv;
		type = myt;
	}
	
	public String toString() {
		return u+"->"+v+" type "+type;
	}
}

public class nothin {
	
	final public static String[] TYPES_LOWER = {"", "off the ", "through the ", "around "};
	final public static String[] TYPES_UPPER = {"", "Off the ", "Through the ", "Around "};
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		
		// Note: They follow every sentence with a blank line. They don't do in between
		//       I'll just do that here.
		
		// Process cases.
		while (stdin.hasNext()) {
			
			// Get locations.
			int n = Integer.parseInt(stdin.nextLine());
			String[] locs = new String[n];
			for (int i=0; i<n-1; i++)
				locs[i] = stdin.nextLine();
				
			// Create graph.
			ArrayList<edge>[] g = new ArrayList[n];
			for (int i=0; i<n; i++) g[i] = new ArrayList<edge>();
			
			// Read in edges.
			for (int i=0; i<n-1; i++) {
				StringTokenizer tok = new StringTokenizer(stdin.nextLine());
				for (int j=0; j<n; j++) {
					int type = Integer.parseInt(tok.nextToken());
					if (type != 0)
						g[i].add(new edge(i,j,type));
				}
			}
			
			// Process queries.
			int s = Integer.parseInt(stdin.nextLine())-1;
			while (s != -1) {
				
				// Get this path and output it.
				ArrayList<edge> path = getPath(g, s, n-1);
				output(g, locs, path);	

				// Get next.
				s = Integer.parseInt(stdin.nextLine())-1;
			}
		}
	}
	
	// Gets the path in g from s to e.
	public static ArrayList<edge> getPath(ArrayList<edge>[] g, int s, int e) {
		
		// Special case.
		if (s == e) return new ArrayList<edge>();
	
		// Set up BFS.
		int n = g.length;
		edge[] prev = new edge[n];
		Arrays.fill(prev, null);
		boolean[] visited = new boolean[n];
		visited[s] = true;
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.offer(s);
		
		// Run BFS.
		while (q.size() > 0) {
			
			// Get next location.
			int cur = q.pollFirst();
			
			// Try all edges from here.
			for (edge nextEdge: g[cur]) {
			
				// Get next place.
				int next = nextEdge.v;
				
				// Been there.
				if (visited[next]) continue;
				
				// Mark it, add to path and queue.
				visited[next] = true;
				prev[next] = nextEdge;
				q.offer(next);
			}
		}
		
		// Add last edge.
		ArrayList<edge> res = new ArrayList<edge>();
		res.add(prev[e]);
		int curV = prev[e].u;
		
		// Add rest of the edges in reverse.
		while (curV != s) {
			res.add(prev[curV]);
			curV = prev[curV].u;
		}
		
		// Put back in order and return.
		Collections.reverse(res);
		return res;
	}
	
	// Outputs the path stored in path.
	public static void output(ArrayList<edge>[] g, String[] locs, ArrayList<edge> path) {
		
		// Special case.
		if (path.size() == 0) {
			System.out.println("Nothin' but net.\n");
			return;
		}
		
		// Start here.
		System.out.print(TYPES_UPPER[path.get(0).type]+locs[path.get(0).u]+", ");
		
		// Do the rest.
		for (int i=1; i<path.size(); i++) {
			System.out.print(TYPES_LOWER[path.get(i).type]+locs[path.get(i).u]+", ");
		}
		
		// Always ends with this.
		System.out.println("nothin' but net.\n");
	}
}