from collections import deque def dfs(g,x): q = deque() q.append(x) dist = [-1]*n dist[x] = 0 cnt = 0 while q: v = q.popleft() for c in g[v]: if dist[c] == -1: dist[c] = dist[v] + 1 q.append(c) cnt += 1 return max(dist),cnt n,m = map(int,input().split()) g = [[] for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) g[a-1].append(b-1) g[b-1].append(a-1) Q = int(input()) for _ in range(Q): v = int(input())-1 res,cnt = dfs(g,v) res = 0 if res==0 else (res-1).bit_length() print(cnt,res)