#include<stdio.h> #include<string.h> int mark,k,m,map[101][101],vis[101][101],h[105]; void seek(int mb) { int q[100],i,s,e; s = e =0; q[e++] = mb; while(s < e) { mb = q[s++]; if(mark) { mark = 0; printf("%d",mb); } else printf(" %d",mb); for(i = 0; i < k; i++) { if( (map[i][mb] && !vis[i][mb]) || (map[mb][i] && !vis[mb][i]) ) { if(!h[i]) { vis[i][mb] = vis[mb][i] = 1; q[e++] = i; h[i] = 1; } } } } } int main() { int js,u,v,i,st; scanf("%d",&js); while(js--) { memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); memset(h,0,sizeof(h)); mark = 1; scanf("%d %d %d",&k,&m,&st); for(i = 0; i < m; i++) { scanf("%d %d",&u,&v); if(u > v) map[u][v] = 1; else map[v][u] = 1; } h[st] = 1; seek(st); for(i = 0; i < k; i++) { if(!h[i]) { seek(i); } } printf("\n"); } return 0; }