import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } StringBuilder sb = new StringBuilder(); int q = sc.nextInt(); PriorityQueue queue = new PriorityQueue<>(); int[] days = new int[n]; while (q-- > 0) { int x = sc.nextInt() - 1; Arrays.fill(days, Integer.MAX_VALUE); queue.add(new Path(x, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (days[p.idx] <= p.value) { continue; } days[p.idx] = p.value; for (int y : graph.get(p.idx)) { queue.add(new Path(y, p.value + 1)); } } int count = -1; int max = 0; for (int y : days) { if (y < Integer.MAX_VALUE) { count++; max = Math.max(max, y); } } sb.append(count).append(" ").append(getDay(max)).append("\n"); } System.out.print(sb); } static int getDay(int d) { int day = 0; int base = 1; while (d > base) { day++; base *= 2; } return day; } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }