#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ struct UnionFind { UnionFind(int sz) : data(sz, -1) {} int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); } void unite(int ver1, int ver2) { ver1 = root(ver1); ver2 = root(ver2); if (ver1 != ver2) { if (data[ver1] > data[ver2]) swap(ver1, ver2); data[ver1] += data[ver2]; data[ver2] = ver1; } } bool same(int ver1, int ver2) { return root(ver1) == root(ver2); } int size(int ver) { return -data[root(ver)]; } private: vector data; }; int day = 0; vector edge[100000]; bool used[100000] = {}; void dfs(int ver, int cnt) { day = max(day, cnt); for (int e : edge[ver]) if (!used[e]) { used[e] = true; dfs(e, cnt + 1); } } int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n, m; cin >> n >> m; UnionFind uf(n); while (m--) { int p, q; cin >> p >> q; --p; --q; uf.unite(p, q); edge[p].emplace_back(q); edge[q].emplace_back(p); } int q; cin >> q; while (q--) { int a; cin >> a; --a; day = 0; memset(used, false, sizeof(used)); used[a] = true; dfs(a, -1); cout << uf.size(a) - 1 << ' ' << day << '\n'; } return 0; }