#include using namespace std; typedef long long ll; typedef pair l_l; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; struct UnionFind { vector par; vector rank; vector Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x){ return Size[root(x)]; } }; vector pathes[100500]; int dist[100050]; int main() { //cout.precision(10); //cin.tie(0); //ios::sync_with_stdio(false); UnionFind uni(100050); int N, M; cin >> N >> M; for(int i = 1; i <= M; i++) { int a, b; cin >> a >> b; uni.merge(a, b); pathes[a].push_back(b); pathes[b].push_back(a); } int Q; cin >> Q; while(Q--) { int A; cin >> A; for(int i = 1; i <= N; i++) dist[i] = INF; dist[A] = 0; queue search; search.push(A); int maxi = 0; while(!search.empty()) { int from = search.front(); maxi = max(maxi, dist[from]); search.pop(); for(int i = 0; i < pathes[from].size(); i++) { int to = pathes[from][i]; if(dist[to] <= dist[from]) continue; dist[to] = dist[from] + 1; search.push(to); } } int day = 0; //cerr << maxi << endl; while(maxi >= 2) { maxi = (maxi + 1) / 2; day++; } cout << uni.size(A) - 1 << " "; cout << day << endl; } return 0; }