public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int[] nm = readInts(in.readLine());
		int n = nm[0], m = nm[1];
		Dijkstra G = new Dijkstra(n + 1);
		G.init(n + 1);
		int[] cost = readInts(in.readLine());
		for (int i = 0; i < cost.length; i++)
			G.cost[i] = cost[i];
		for (int i = 0; i < m; i++) {
			int[] uvl = readInts(in.readLine());
			int u = uvl[0], v = uvl[1], l = uvl[2];
			G.union(u, v, l, true);
		}
		int queries = Integer.parseInt(in.readLine().trim());
		for (int i = 0; i < queries; i++) {
			int[] cuv = readInts(in.readLine());
			int u = cuv[1], v = cuv[2], c = cuv[0];
			int ans = G.dijkstra(u, v, c);
			if (ans == G.INF)
				out.append("impossible\n");
			else
				out.append(ans + "\n");
		}
		System.out.print(out);
	}