#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int a[105][105];
int vis[105];
int qu[10005], front, tail, flag, n;
void init()
{
memset(a, 0, sizeof(a));
memset(vis, 0, sizeof(vis));
front = tail = flag = 0;
}
void dfs(int x)
{
if(flag == 0){printf("%d", x); flag = 1;}
else printf(" %d", x);
vis[x] = 1;
for(int i = 0; i < n; i++)
{
if(a[x][i] == 1 && vis[i] == 0)dfs(i);
}
}
int main()
{
int t, m, i, j;
scanf("%d", &t);
while(t--)
{
init();
scanf("%d %d", &n, &m);
for(i = 1; i <= m; i++)
{
int u, v;
scanf("%d %d", &u, &v);
a[u][v] = a[v][u] = 1;
}
dfs(0);
printf("\n");
}
return 0;
}