#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, t1, t2, t3, par[100005];
ll t, q, dist[100005];
priority_queue<pll, vector<pll>, greater<pll>> pq;
vector<pll> adj[100005];
pll a[100005], qu[100005];
ll lb[100005], ub[100005];
pll tq[100005];
ll ci;
bool ac[100005];
ll find(ll x) {
return (par[x] == x ? x : par[x] = find(par[x]));
}
void merge(ll x, ll y) {
x = find(x), y = find(y);
if (x != y) par[x] = y;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
iloop(0, m) {
cin >> t1 >> t2 >> t3;
t1--, t2--;
adj[t1].push_back({t3, t2});
adj[t2].push_back({t3, t1});
}
iloop(0, n) dist[i] = INF;
cin >> t;
iloop(0, t) {
cin >> t1;
t1--;
dist[t1] = 0;
pq.push({0, t1});
}
while (pq.size()) {
pll nd = pq.top();
pq.pop();
if (dist[nd.second] < nd.first) continue;
for (auto it : adj[nd.second]) {
if (it.first + nd.first < dist[it.second]) {
dist[it.second] = it.first + nd.first;
pq.push({dist[it.second], it.second});
}
}
}
iloop(0, n) a[i] = {dist[i], i};
sort(a, a+n, greater<pll>());
cin >> q;
iloop(0, q) {
cin >> qu[i].first >> qu[i].second;
qu[i].first--, qu[i].second--;
lb[i] = 0, ub[i] = INF;
}
jloop(0, 60) {
iloop(0, q) tq[i] = {(lb[i] + ub[i] + 1)>>1, i};
sort(tq, tq+q, greater<pll>());
iloop(0, n) par[i] = i, ac[i] = 0;
ci = 0;
iloop(0, n) {
while (ci < q && tq[ci].first > a[i].first) {
if (find(qu[tq[ci].second].first) == find(qu[tq[ci].second].second)) lb[tq[ci].second] = tq[ci].first;
else ub[tq[ci].second] = tq[ci].first - 1;
ci++;
}
ac[a[i].second] = 1;
for (auto it : adj[a[i].second]) if (ac[it.second]) merge(a[i].second, it.second);
}
while (ci < q) {
lb[tq[ci].second] = tq[ci].first;
ci++;
}
}
iloop(0, q) cout << lb[i] << "\n";
}