int ans[1000];
int main(int argc, char const* argv[])
{
int t;
bool first = true;
while(~scanf("%d",&t)){
while(t--){
vector<int> P[1000];
bool visit[1000] = {false};
if(!first){
printf("\n");
}
int p,d;
scanf("%d %d",&p,&d);
while(d--){
int p1,p2;
scanf("%d %d ...