#include #include #include #include #include #include #include using namespace std; using lint = long long; const lint mod = 1000000007; #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) template inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } templateint character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; } lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; template string to_string(pair x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; } template void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; } template void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template T lcm(T a, T b){ return a / gcd(a, b) * b; } struct combination{ vector fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; template bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; } template< typename T > struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template< typename T > using Edges = vector< edge< T > >; template< typename T > using WeightedGraph = vector< Edges< T > >; using UnWeightedGraph = vector< vector< int > >; template< typename T > using Matrix = vector< vector< T > >; struct UnionFind { vector< int > data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if(x == y) return(false); if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return(true); } int find(int k) { if(data[k] < 0) return(k); return(data[k] = find(data[k])); } int size(int k) { return(-data[find(k)]); } }; template< typename T > vector< T > dijkstra(WeightedGraph< T > &g, int s) { const auto INF = numeric_limits< T >::max(); vector< T > dist(g.size(), INF); using Pi = pair< T, int >; priority_queue< Pi, vector< Pi >, greater< Pi > > que; dist[s] = 0; que.emplace(dist[s], s); while(!que.empty()) { T cost; int idx; tie(cost, idx) = que.top(); que.pop(); if(dist[idx] < cost) continue; for(auto &e : g[idx]) { auto next_cost = cost + e.cost; if(dist[e.to] <= next_cost) continue; dist[e.to] = next_cost; que.emplace(dist[e.to], e.to); } } return dist; } int main(){ int N, M; cin >> N >> M;; WeightedGraph roads(N); for(int i = 0; i < M; i++){ int p, q; cin >> p >> q; p--, q--; roads[p].push_back(edge(q, 1)); roads[q].push_back(edge(p, 1)); } int Q; cin >> Q; for(int i = 0; i < Q; i++){ int A; cin >> A; A--; auto dist = dijkstra(roads, A); int ans = 0, sum = 0; for(int j = 0; j < N; j++){ if(dist[j] < 1e9){ sum++; ans = max(ans, dist[j]); } } ans--; int ans2 = 0; while(ans > 0){ ans /= 2; ans2++; } cout << sum - 1 << " " << ans2 << endl; } }