#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int check(int x) { int cnt = 0; while (x > 0) { x /= 2; cnt++; } return cnt; } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); int n, m, q; cin >> n >> m; vector g[n]; rep (i, m) { int s, t; cin >> s >> t; g[s - 1].push_back(t - 1); g[t - 1].push_back(s - 1); } cin >> q; rep (i, q) { int a; cin >> a; a--; if (g[a].size() == 0) { cout << 0 << " " << 0 << endl; continue; } int cnt = 0; int day = 0; vector checked(n, Inf); queue q; rep (j, g[a].size()) { q.push(g[a][j]); checked[g[a][j]] = 0; cnt++; } checked[a] = 0; while (!q.empty()) { int next = q.front(); q.pop(); rep (j, g[next].size()) { if (checked[g[next][j]] < checked[next] + 1) continue; checked[g[next][j]] = checked[next] + 1; q.push(g[next][j]); cnt++; } int tmp = check(checked[next]); day = max(day, tmp); } cout << cnt << " " << day << endl; } return 0; }