#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  UnionFind uf(n);
  while (m--) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    uf.unite(u, v);
  }
  int q; cin >> q;
  while (q--) {
    int a; cin >> a, --a;
    V<> d(n, -1);
    queue<int> que;
    d[a] = 0;
    que.emplace(a);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int w : g[v]) if (d[w] == -1) {
        d[w] = d[v] + 1;
        que.emplace(w);
      }
    }
    int mx = *max_element(begin(d), end(d));
    cout << uf.size(a) - 1 << ' ' << !!(uf.size(a) - 1) * __lg(2 * mx - 1) << '\n';
  }
}