#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif
struct DSU {
vector<int> p;
vector<set<int>> a;
DSU(int n) {
p.assign(n + 1, -1);
a.resize(n + 1);
for (int i = 1; i <= n; i++) {
a[i].insert(i);
}
}
int root(int x) { return (p[x] == -1 ? x : (p[x] = root(p[x]))); }
bool link(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
p[y] = x;
if (a[x].size() < a[y].size()) {
swap(a[x], a[y]);
}
for (auto k : a[y]) {
a[x].insert(k);
}
a[y].clear();
return true;
}
};
constexpr int N = 1e5 + 1;
constexpr int inf = 1e9;
int dist[N];
vector<array<int, 2>> g[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<array<int, 2>> e;
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
e.push_back({u, v});
g[u].push_back({v, w});
g[v].push_back({u, w});
}
fill(dist, dist + N, inf);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
int k;
cin >> k;
for (int i = 0; i < k; i++) {
int u;
cin >> u;
dist[u] = 0;
q.emplace(0, u);
}
while (!q.empty()) {
auto [s, u] = q.top();
q.pop();
if (dist[u] < s) continue;
for (auto [v, w] : g[u]) {
if (s + w < dist[v]) {
dist[v] = s + w;
q.emplace(s + w, v);
}
}
}
int t;
cin >> t;
vector<array<int, 3>> qs(t);
for (int i = 0; i < t; i++) {
cin >> qs[i][0] >> qs[i][1];
qs[i][2] = i;
}
vector<array<int, 2>> x(n + 1);
for (int i = 1; i <= n; i++) {
x[i] = {dist[i], i};
}
ranges::sort(x);
DSU dsu(n + 1);
vector<int> ans(t);
vector<bool> allowed(n + 1);
for (int ptr = n; ptr >= 1; ptr--) {
auto [d, u] = x[ptr];
allowed[u] = 1;
for (auto [v, _] : g[u]) {
if (allowed[v]) {
dsu.link(u, v);
}
}
int x = dsu.root(u);
for (auto [i, j, idx] : qs) {
auto &s = dsu.a[x];
if (s.count(i) && s.count(j) && ans[idx] == 0) {
ans[idx] = d;
}
}
}
for (int i = 0; i < t; i++) {
cout << ans[i] << '\n';
}
return 0;
}