from collections import deque N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): p, q = (int(x) - 1 for x in input().split()) G[p].append(q) G[q].append(p) def solve(a): dist = [-1] * N dist[a] = 0 # bfs d = deque([a]) num = 0 while d: v = d.popleft() dx = dist[v] + 1 for x in G[v]: if dist[x] == -1: num += 1 dist[x] = dx d.append(x) m = max(dist) day = (m - 1).bit_length() if m else 0 return num, day Q = int(input()) for _ in range(Q): a = int(input()) - 1 print(*solve(a))