#include #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair P; const int mod = 1000000007; const int INF = 1e18; int n, m; vector G[100010]; int d[100010]; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n >> m; rep(i, 0, m){ int p, q; cin >> p >> q; p--; q--; G[p].push_back(q); G[q].push_back(p); } int Q; cin >> Q; while(Q--){ int a; cin >> a; a--; rep(i, 0, n) d[i] = -1; queue q; q.push(a); d[a] = 0; while(!q.empty()){ int tmp = q.front(); q.pop(); for(auto i : G[tmp]){ if(d[i] != -1) continue; d[i] = d[tmp] + 1; q.push(i); } } int ans = 0, day = 0; rep(i, 0, n){ if(d[i] != -1){ ans++; day = max(day, d[i]); } } if(ans == 0) cout << 0 << ' ' << 0 << endl; else{ int now = 1; for(int j = 0;; j++){ if(day <= now){ day = j; break; } now *= 2; } cout << ans - 1 << ' ' << day << endl; } } }