#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//#define int ll
using P = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(i, l, n) for (int i = l; i < (n); ++i)
#define sz(x) (int)x.size()
const char nl = '\n';
const int N = 1e5+10;
const int inf = 1e8+10;
int a[N], s[N];
vector<int> S[N];
struct nd {
int w, u, v;
};
bool cmp(nd x, nd y) {
return x.w > y.w;
}
int find(int x) {
if (a[x] == x)return x;
return a[x] = find(a[x]);
}
void solve() {
int n, m; cin >> n >> m;
rep(i, 1, n+1) {
a[i] = i, s[i] = 1;
S[i].push_back(i);
}
vector<nd> e(m);
vector<P> g[n+1];
rep(i, 0, m) {
int u, v, w; cin >> u >> v >> w;
e[i] = {0, u, v};
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<int> d(n+1, inf);
priority_queue<P, vector<P>, greater<P>> pq;
int k; cin >> k;
while (k--) {
int x; cin >> x;
d[x] = 0;
pq.push({x, 0});
}
while (!pq.empty()) {
auto [x, y] = pq.top(); pq.pop();
if (d[x] != y)continue;
for (auto [i, w]: g[x])
if (d[i] > y+w) {
d[i] = y+w;
pq.push({i, y+w});
}
}
for (auto &i: e)
i.w = min(d[i.u], d[i.v]);
sort(all(e), cmp);
map<int, int> mp[n+1];
rep(i, 1, n+1)
mp[i][i] = inf;
for (auto i: e) {
int x = i.u, y = i.v;
x = find(x), y = find(y);
if (x == y)continue;
if (s[x] > s[y])swap(x, y);
a[x] = y, s[y] += s[x];
for (auto j: S[x]) {
S[y].push_back(j);
mp[j][y] = i.w;
//cout << j << " " << y << " " << i.w << nl;
}
}
int q; cin >> q;
while (q--) {
int x, y; cin >> x >> y;
int res = 0;
for (auto j: mp[x]) {
if (mp[y].find(j.first) == mp[y].end())continue;
res = max(res, min(mp[y][j.first], j.second));
}
cout << res << nl;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}