from collections import deque import sys sys.setrecursionlimit(200000) n, m = map(int, input().split()) info = [list(map(int, input().split())) for i in range(m)] q = int(input()) a = [int(input()) for i in range(q)] tree = [[] for i in range(n)] for i in range(m): tree[info[i][0] - 1].append(info[i][1] - 1) tree[info[i][1] - 1].append(info[i][0] - 1) def bfs(a): visited = [False]*n cnt = 0 q = deque([]) q.append([0, a]) visited[a] = True while q: times, pos = q.popleft() for next_pos in tree[pos]: if not visited[next_pos]: visited[next_pos] = True cnt += 1 q.append([times + 1, next_pos]) if times == 1: times = 0 else: times = -(-(times) // 2) cnt = cnt return times, cnt for i in range(q): ans1, ans2 = bfs(a[i] - 1) print(ans2, ans1)