#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N, M; cin >> N >> M; vector> g(N); REP(i, M) { int p, q; scanf("%d %d", &p, &q); --p; --q; g[p].emplace_back(q); g[q].emplace_back(p); } auto func = [&](int st) -> pii { vector dist(N, INF); queue que; dist[st] = 0; que.emplace(st); int cnt = 0, mxd = 0; while (!que.empty()) { int u = que.front(); que.pop(); ++cnt; chmax(mxd, dist[u]); for (int v : g[u]) if (chmin(dist[v], dist[u] + 1)) que.emplace(v); } return {cnt, mxd}; }; int Q; cin >> Q; while (Q--) { int A; scanf("%d", &A); --A; auto [cnt, mxd] = func(A); --cnt; if (mxd <= 1) printf("%d %d\n", cnt, 0); else { for (int i = 16; i >= 0; --i) if ((mxd - 1) >> i & 1) { printf("%d %d\n", cnt, i + 1); break; } } } }