#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

void dijkstra(int n, vector<vector<edge> >& G, vector<int>& t, int s, vector<ll>& d, vector<int>& prev) {
	fill(d.begin(), d.end(), LLONG_MAX); d[s] = 0;
	fill(prev.begin(), prev.end(), -1);
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > q;
	q.push(ll_i(0, s));
	while (!q.empty()) {
		ll_i p = q.top(); q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] >= d[u] + e.w)
				if (d[e.v] > d[u] + e.w || prev[e.v] == -1 || t[prev[e.v]] > t[u])
					prev[e.v] = u;
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				q.push(ll_i(d[e.v], e.v));
			}
		}
	}
}

int parent[20][100000];
int depth[100000];
 
void init(int N) {
	for (int k = 0; k + 1 < 20; k++)
		for (int v = 0; v < N; v++)
			if (parent[k][v] < 0) parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> t(N);
	for (int u = 0; u < N; u++)
		scanf("%d", &t[u]);
	vector<vector<edge> > G(N);
	while (M--) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		a--; b--; ll w = (ll)c * 1000000 + 1;
		G[a].push_back(edge{a, b, w});
		G[b].push_back(edge{b, a, w});
	}
	vector<ll> d(N);
	vector<int> prev(N);
	dijkstra(N, G, t, 0, d, prev);
	for (int u = 0; u < N; u++) {
		parent[0][u] = prev[u];
		depth[u] = d[u] % 1000000;
	}
	init(N);
	int K; cin >> K;
	while (K--) {
		int x, day, p; scanf("%d%d%d", &x, &day, &p);
		x--;
		int y = x, up = max(0, depth[x] - day);
		for (int k = 0; k < 20; k++)
			if (up>>k & 1)
				y = parent[k][y];
		printf("%lld\n", d[x] / 1000000 - d[y] / 1000000 + max(0LL, d[y] / 1000000 - p));
	}
}