#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n>>m; vector > G(n); for(Int i=0;i>x>>y; x--;y--; G[x].emplace_back(y); G[y].emplace_back(x); } Int q; cin>>q; while(q--){ Int s; cin>>s; s--; Int cnt=0; vector dist(n,-1); queue q; dist[s]=0; q.emplace(s); while(!q.empty()){ Int v=q.front();q.pop(); cnt++; for(Int u:G[v]){ if(~dist[u]) continue; dist[u]=dist[v]+1; q.emplace(u); } } Int d=*max_element(dist.begin(),dist.end()); Int ans=0; while(d>(1<