#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; constexpr int INF = 1e9; struct UnionFind{ vector data; int __size; UnionFind(int sz) { data.assign(sz, -1); __size = sz; } 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);//親は負でサイズを保存 __size--; 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])); } bool same(int x, int y){ return find(x) == find(y); } int size(int k) { return (-data[find(k)]); } int unum() { return (__size); } }; int main(){ int n, m; cin >> n >> m; vector> g(n); UnionFind uf(n); rep(i,m) { int u, v; cin >> u >> v; u--; v--; g[u].emplace_back(v); g[v].emplace_back(u); uf.unite(u, v); } auto bfs = [&](int s) { vector d(n,INF); queue que; que.push(s); d[s] = 0; int res = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (auto v : g[u]) { if (d[v] != INF) continue; d[v] = d[u] + 1; res = max(res, d[v]); que.push(v); } } return res; }; int q; cin >> q; while (q--) { int a; cin >> a; a--; if (uf.size(a) == 1) { cout << 0 << " " << 0 << endl; } else { int h = bfs(a); int d = 0; while ( (1 << d) < h) d++; cout << uf.size(a) - 1 << " " << d << endl; } } return 0; }