#include using namespace std; int t,n,m,x,y,a[1001][1001],chuaxet[1001],i,j,k; void DFS(int u){ stack q; q.push(u); chuaxet[u]=1; cout << u << " "; while(!q.empty()){ u=q.top(); q.pop(); for(int v=1;v<=n;v++){ if(chuaxet[v]==0&&a[u][v]==1){ cout << v << " "; chuaxet[v]=1; q.push(u); q.push(v); break; } } } } int main(){ cin >> t; while(t--){ cin >> n >> m; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ a[i][j]=0; chuaxet[j]=0; } } for(i=1;i<=m;i++){ cin >> x >> y; a[x][y]=a[y][x]=1; } for(k=1;k<=n;k++){ if(chuaxet[k]==0){ DFS(k); cout << endl; } } } }