import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import deque import bisect N = 32 P = [0]*N P[0] = 1 for i in range(1, N): P[i] = P[i-1]*2 n, m = map(int,input().split()) g = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x, y = x-1, y-1 g[x].append(y) g[y].append(x) q = int(input()) Q = [] for i in range(q): a = int(input()) a -= 1 Q.append(a) for a in Q: q = deque([]) q.append(a) dist = [-1]*n dist[a] = 0 while q: v = q.popleft() for u in g[v]: if dist[u] != -1: continue dist[u] = dist[v]+1 q.append(u) cnt = 0 M = 0 for i in range(n): if dist[i] != -1: cnt += 1 M = max(M, dist[i]) t = bisect.bisect_left(P, M) print(cnt-1, t)