public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		init(201);
		int nSet = 1;
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] data;
			try {
				data = readInts(line);
			} catch (Exception e) {
				break;
			}
			int n = data[0];
			clean();
			for (int i = 0; i < n; i++)
				cost[i] = data[i + 1];
			int edges = Integer.parseInt(in.readLine().trim());
			for (int i = 0; i < edges; i++) {
				int[] uv = readInts(in.readLine());
				int u = uv[0] - 1, v = uv[1] - 1;
				adj[u].add(new Edge(v, (int) Math.pow(cost[v] - cost[u], 3)));
			}
			out.append("Set #" + nSet++ + "\n");
			bellmanFord(0);
			int q = Integer.parseInt(in.readLine().trim());
			for (int i = 0; i < q; i++) {
				int t = Integer.parseInt(in.readLine().trim()) - 1;
				if (dist[t] < 3 || dist[t] == INF || cycle[t])
					out.append("?\n");
				else
					out.append(dist[t] + "\n");
			}
		}
		System.out.print(out);
	}