#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; void dijkstra(ll start, vector>>& graph, vector& dist) { dist[start] = 0; priority_queue, vector>, greater>> pq; vector used(dist.size(), false); pq.push(make_pair(0, start)); while (!pq.empty()) { ll d, node; tie(d, node) = pq.top(); pq.pop(); if (used[node]) continue; used[node] = true; for (pair element : graph[node]) { ll new_d, new_node; tie(new_node, new_d) = element; new_d += d; if (new_d < dist[new_node]) { dist[new_node] = new_d; pq.push(make_pair(dist[new_node], new_node)); } } } } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n, m; scanf("%lld %lld", &n, &m); vector>> g(n); for (ll i = 0; i < m; i++) { ll p, q; scanf("%lld %lld", &p, &q); p--; q--; g[p].emplace_back(q, 1); g[q].emplace_back(p, 1); } ll q; scanf("%lld", &q); while (q--) { ll a; scanf("%lld", &a); a--; vector d(n, INF); d[a] = 0; dijkstra(a, g, d); ll cnt = 0; ll time = 0; for (ll i = 0; i < n; i++) { if (d[i] == INF) continue; cnt++; if (d[i] > 1) chmax(time, d[i] - 1); } printf("%lld %lld\n", cnt - 1, time); } return 0; }