#include using namespace std; using ll = long long; const int INF = 1e9; vector bfs(int src, int n, vector< vector >& g) { vector res(n, INF); res[src] = 0; queue q; q.push(src); while (!q.empty()) { int cur = q.front(); q.pop(); for (int nex : g[cur]) { if (res[nex] != INF) continue; res[nex] = res[cur] + 1; q.push(nex); } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector< vector > g(n); for (int i = 0; i < m; i++) { int p, q; cin >> p >> q; p--; q--; g[p].push_back(q); g[q].push_back(p); } int q; cin >> q; for (int i = 0; i < q; i++) { int a; cin >> a; a--; vector d = bfs(a, n, g); int cnt = 0; int maxd = 0; for (int j = 0; j < n; j++) { if (d[j] == INF) continue; cnt++; maxd = max(maxd, d[j]); } cnt = max(cnt - 1, 0); int ans = 0; if (maxd > 0) { for (int j = 0; j <= 17; j++) { if (maxd <= (1 << j)) { ans = j; break; } } } cout << cnt << " " << ans << "\n"; } return 0; }