#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

struct edge {
    int to;
    edge(int to) :to(to){}
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<edge>> G(N,vector<edge>());
    for (int i = 0; i < M; i++)
    {
        int p, q;
        cin >> p >> q;
        p--; q--;
        G[p].push_back(edge(q));
        G[q].push_back(edge(p));
    }
    int Q;
    cin >> Q;
    vector<bool> visited(N);
    vector<P> ans(Q);
    for (int i = 0; i < Q; i++)
    {
        int a, m = -1, cnt = -1;
        cin >> a;
        a--;
        queue<P> que;
        fill(visited.begin(), visited.end(), false);
        que.push(P(a,0));
        while (!que.empty()) {
            P p = que.front(); que.pop();
            if (visited[p.first]) continue;
            visited[p.first] = true;
            cnt++;
            for (int j = 0; j < G[p.first].size(); j++)
            {
                que.push(P(G[p.first][j].to, p.second + 1));
            }
            m = max(m, p.second);
        }
        ans[i].first = cnt;
        ans[i].second = max(0,m-1);
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    getchar(); getchar();
    return 0;
}