#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque N, M = map(int, readline().split()) PQ = [tuple(map(int, readline().split())) for _ in range(M)] Q = int(readline()) A = tuple(int(readline()) for _ in range(Q)) G = [[] for _ in range(N + 1)] for p, q in PQ: G[p].append(q) G[q].append(p) def bfs(root): dist = [-1] * (N + 1) q = deque() q.append(root) dist[root] = 0 while q: v = q.popleft() dw = dist[v] + 1 for w in G[v]: if dist[w] == -1: dist[w] = dw q.append(w) return dist for a in A: dist = bfs(a) max_d = max(dist) if max_d == 0: print(0, 0) continue n = (max_d - 1).bit_length() friend = sum(x > 0 for x in dist) print(friend, n)