#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second

typedef long long ll;
typedef pair<int,int> pii;
const int N = 200+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, m;
int a[N];
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int tc = 1;
	while(cin >> n){
		for(int i=1; i<=n; i++) cin >> a[i];
		vector<tuple<int,int,int>> edges;
		vector<int> g[n+2];
		cin >> m;
		while(m--){
			int u, v; cin >> u >> v;
			edges.push_back({u, v, pow(a[v]-a[u], 3)});
			g[u].push_back(v);
		}
		vector<int> d(n+2, INF);
		d[1] = 0; //source 1
		for(int i=1; i<=n-1; i++){
			for(auto e:edges){
				int u, v, w; tie(u, v, w) = e;
				// what_is(u); what_is(v); what_is(w);
				if (d[u] == INF) continue;
				d[v] = min(d[v], d[u]+w);
			}
		}

		for(auto e:edges){
			int u, v, w; tie(u, v, w) = e;
			if (d[u] == INF) continue;
			if (d[u] + w < d[v]) {
				d[v] = -INF;
			}
		}
		int q; cin >> q;
		cout << "Set #" << tc++ << endl;
		while(q--){
			int des; cin >> des;
			if (d[des] < 3 || d[des] == INF) cout << "?" << endl;
			else cout << d[des] << endl;
		}
	}

	return 0;
}
