You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.

Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices.

It is guaranteed that the answer exists. If there are multiple answers, you can print any.

You will be given multiple independent queries to answer.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of queries.

Then $t$ queries follow.

The first line of each query contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges, respectively.

The following $m$ lines denote edges: edge $i$ is represented by a pair of integers $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$), which are the indices of vertices connected by the edge.

There are no self-loops or multiple edges in the given graph, i. e. for each pair ($v_i, u_i$) there are no other pairs ($v_i, u_i$) or ($u_i, v_i$) in the list of edges, and for each pair ($v_i, u_i$) the condition $v_i \ne u_i$ is satisfied. It is guaranteed that the given graph is connected.

It is guaranteed that $\sum m \le 2 \cdot 10^5$ over all queries.


-----Output-----

For each query print two lines.

In the first line print $k$ ($1 \le \lfloor\frac{n}{2}\rfloor$) — the number of chosen vertices.

In the second line print $k$ distinct integers $c_1, c_2, \dots, c_k$ in any order, where $c_i$ is the index of the $i$-th chosen vertex.

It is guaranteed that the answer exists. If there are multiple answers, you can print any.


-----Example-----
Input
2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
6 8
2 5
5 4
4 3
4 1
1 3
2 3
2 6
5 6

Output
2
1 3
3
4 3 6



-----Note-----

In the first query any vertex or any pair of vertices will suffice.

 [Image] 

Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices $2$ and $4$) but three is also ok.

 [Image]

Difficulty: introductory

Starter code:

Solutions:
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
    N, M = list(map(int, input().split()))
    E = [[] for aa in range(N)]
    for __ in range(M):
        a, b = list(map(int, input().split()))
        E[a-1].append(b-1)
        E[b-1].append(a-1)
    
    D = [-1] * N
    D[0] = 0
    d = 0
    post = [0]
    EVEN = [1]
    ODD = []
    while post:
        d += 1
        pre = post
        post = []
        for i in pre:
            for e in E[i]:
                if D[e] < 0:
                    D[e] = d
                    post.append(e)
                    if d % 2:
                        ODD.append(e+1)
                    else:
                        EVEN.append(e+1)
    if len(ODD) < len(EVEN):
        print(len(ODD))
        print(*ODD)
    else:
        print(len(EVEN))
        print(*EVEN)


import sys
input = sys.stdin.readline
from collections import deque

Q=int(input())

for q in range(Q):
    n,m=list(map(int,input().split()))

    E=[list(map(int,input().split())) for i in range(m)]

    ELIST=[[] for i in range(n+1)]
    for a,b in E:
        ELIST[a].append(b)
        ELIST[b].append(a)

    check=[0]*(n+1)
    ANS=[]

    Q=deque([1])
    E2=[[] for i in range(n+1)]

    while Q:
        x=Q.pop()
        check[x]=1
        for to in ELIST[x]:
            if check[to]==0:
                E2[x].append(to)
                E2[to].append(x)
                check[to]=1
                Q.append(to)

    #print(E2)
    ELIST=E2

    check=[0]*(n+1)
    

    QUE=deque([])
    QUE.append([1,0])

    while QUE:
        x,point=QUE.pop()
        if point==0:
            if check[x]==1:
                continue
            check[x]=1
            ANS.append(x)

            for to in ELIST[x]:
                if check[to]==0:
                    check[to]=1
                    QUE.appendleft([to,1])

        else:
            for to in ELIST[x]:
                if check[to]==0:
                    QUE.appendleft([to,0])


    if len(ANS)<=n//2:

        print(len(ANS))
        print(*ANS)
        continue
    

    check=[0]*(n+1)
    ANS=[]

    QUE=deque([])
    QUE.append([ELIST[1][0],0])

    while QUE:
        x,point=QUE.pop()
        if point==0:
            if check[x]==1:
                continue
            check[x]=1
            ANS.append(x)

            for to in ELIST[x]:
                if check[to]==0:
                    check[to]=1
                    QUE.appendleft([to,1])

        else:
            for to in ELIST[x]:
                if check[to]==0:
                    QUE.appendleft([to,0])

    print(len(ANS))
    print(*ANS)
    


import sys
from collections import deque 
for _ in range(int(input())):
    n,m=list(map(int,sys.stdin.readline().split()))
    a=[[] for i in range(n+1)]
    for i in range(m):
        x,y=list(map(int,sys.stdin.readline().split()))
        a[x].append(y)
        a[y].append(x)
    col=[-1]*(n+1)
    col[1]=1
    d=deque([1])
    vis=[0]*(n+1)
    # vis[1]=1
    ans=[[],[1]]
    
    while d:
        p=d.popleft()
        for i in a[p]:
            if col[i]==-1:
                col[i]=1-col[p]
                ans[1-col[p]].append(i)
                d.append(i)
    
    if len(ans[0])<=n//2:
        print(len(ans[0]))
        
        print(*ans[0])
    else:
        print(len(ans[1]))
        
        print(*ans[1])


from collections import deque
import sys


for _ in range(int(sys.stdin.readline())):
    n, m = list(map(int, sys.stdin.readline().split()))
    g = [[] for _ in range(n + 1)]
    
    for _ in range(m):
        a, b = list(map(int, sys.stdin.readline().split()))
        g[a].append(b)
        g[b].append(a)
        
    k = [[], [1]]
    color = [-1] * (n + 1)
    m = deque([1])
    color[1] = 1
    while m:
        u = m.popleft()
        for v in g[u]:
            if color[v] == -1:
                color[v] = 1 - color[u]
                k[color[v]].append(v)
                m.append(v) 
                
    if len(k[0]) <= n // 2:
        print(len(k[0]))
        print(*k[0])
        
    else:
        print(len(k[1]))
        print(*k[1])


######################################################################
# Write your code here
import sys
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
#import heapq 
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
#infinite = float('inf')
#######################################################################)
def dfs(a,n):
    depth=[0]*n
    depth[a]=0
    x=1
    stack=[a]
    vis[a]=1
    l=[0,0]
    l[0]+=1
    #stackindex=0
    #print(stack)
    while(len(stack)!=0):
        
        p=stack.pop()
        #print(p)
        #stackindex-=1
        for i in adj[p]:
            if(vis[i]==1):
                continue
            vis[i]=1
            stack.append(i)
            #stackindex+=1
            depth[i]=depth[p]^1
            l[depth[i]]+=1
        x=(x+1)%2
        #print(depth)
        #print(vis)
        #print("hi")
    #print(depth)
    #print(l)
    
    s=n//2
    if(l[0]<=s):
        print(l[0])
        for i in range(n):
            if(depth[i]==0):
                print(i+1,end=" ")
    else:
        print(l[1])
        for i in range(n):
            if(depth[i]==1):
                print(i+1,end=" ")
    print("")
    
            


t=int(input())

adj=[[] for i in range(200010)]
vis=[0]*(200010)
for _ in range(t):
    n,m=RI()

    for i in range(n):
        adj[i].clear()
        vis[i]=0
    for i in range(m):
        a,b=RI()
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    #print(adj)
   # print("hi",0)
    dfs(0,n)

######################################################################
# Write your code here
import sys
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in input().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
#import heapq 
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
#infinite = float('inf')
#######################################################################)
def dfs(a,n):
    depth=[0]*n
    depth[a]=0
    x=1
    stack=[a]
    vis[a]=1
    l=[0,0]
    l[0]+=1
    #stackindex=0
    #print(stack)
    while(len(stack)!=0):
        
        p=stack.pop()
        #print(p)
        #stackindex-=1
        for i in adj[p]:
            if(vis[i]==1):
                continue
            vis[i]=1
            stack.append(i)
            #stackindex+=1
            depth[i]=depth[p]^1
            l[depth[i]]+=1
        x=(x+1)%2
        #print(depth)
        #print(vis)
        #print("hi")
    #print(depth)
    #print(l)
    
    s=n//2
    if(l[0]<=s):
        print(l[0])
        for i in range(n):
            if(depth[i]==0):
                print(i+1,end=" ")
    else:
        print(l[1])
        for i in range(n):
            if(depth[i]==1):
                print(i+1,end=" ")
    print("")
    
            


t=int(input())

adj=[[] for i in range(200010)]
vis=[0]*(200010)
for _ in range(t):
    n,m=RI()

    for i in range(n):
        adj[i].clear()
        vis[i]=0
    for i in range(m):
        a,b=RI()
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    #print(adj)
   # print("hi",0)
    dfs(0,n)

######################################################################
# Write your code here
import sys
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in input().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
#import heapq 
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
#infinite = float('inf')
#######################################################################)
def dfs(a,n):
    depth=[0]*n
    depth[a]=0
    x=1
    stack=[a]
    vis[a]=1
    l=[0,0]
    l[0]+=1
    #stackindex=0
    #print(stack)
    while(len(stack)!=0):
        
        p=stack.pop()
        #print(p)
        #stackindex-=1
        for i in adj[p]:
            if(vis[i]==1):
                continue
            vis[i]=1
            stack.append(i)
            #stackindex+=1
            depth[i]=depth[p]^1
            l[depth[i]]+=1
        x=(x+1)%2
        #print(depth)
        #print(vis)
        #print("hi")
    #print(depth)
    #print(l)
    
    s=n//2
    if(l[0]<=s):
        print(l[0])
        for i in range(n):
            if(depth[i]==0):
                print(i+1,end=" ")
    else:
        print(l[1])
        for i in range(n):
            if(depth[i]==1):
                print(i+1,end=" ")
    print("")
    
            


t=int(input())

#adj=[[] for i in range(200010)]
#vis=[0]*(200010)
for _ in range(t):
    n,m=RI()

    adj=[[] for i in range(n)]
    vis=[0]*(n)
    for i in range(m):
        a,b=RI()
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    #print(adj)
   # print("hi",0)
    dfs(0,n)


# -*- coding: utf-8 -*-
# @Date    : 2019-06-11 10:26:57
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


from collections import deque

for _ in range(RI()):
    n, m = RMI()
    a = [[] for i in range(n + 1)]
    for i in range(m):
        x, y = RMI()
        a[x].append(y)
        a[y].append(x)
    col = [-1] * (n + 1)
    col[1] = 1
    d = deque([1])
    vis = [0] * (n + 1)
    ans = [[], [1]]
    while d:
        p = d.popleft()
        for i in a[p]:
            if col[i] == -1:
                tog = 1 - col[p]
                col[i] = tog
                ans[tog].append(i)
                d.append(i)
    if len(ans[0]) <= n // 2:
        print(len(ans[0]))
        print(*ans[0])
    else:
        print(len(ans[1]))
        print(*ans[1])


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
    N, M = map(int, input().split())
    E = [[] for aa in range(N)]
    for __ in range(M):
        a, b = map(int, input().split())
        E[a-1].append(b-1)
        E[b-1].append(a-1)
    
    D = [-1] * N
    D[0] = 0
    d = 0
    post = [0]
    EVEN = [1]
    ODD = []
    while post:
        d += 1
        pre = post
        post = []
        for i in pre:
            for e in E[i]:
                if D[e] < 0:
                    D[e] = d
                    post.append(e)
                    if d % 2:
                        ODD.append(e+1)
                    else:
                        EVEN.append(e+1)
    if len(ODD) < len(EVEN):
        print(len(ODD))
        print(*ODD)
    else:
        print(len(EVEN))
        print(*EVEN)

import sys
input = sys.stdin.readline

def jiashen(new_tree):
    nonlocal g
    nonlocal k
    js = []
    for i in new_tree:
        for j in gra[i]:
            if (fil[j]):
                fil[j] = 0
                js.append(j)
                g += 1
                if (k):
                    d2.append(j)
                else:
                    d1.append(j)
    k = False if k else True
    return js

t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    gra = [[] for i in range(n)]
    d1 = [0]
    d2 = []
    fil = [1 for i in range(n)]
    fil[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        gra[a-1].append(b-1)
        gra[b-1].append(a-1)
    new_tree = [0]
    k = True
    g = 1
    while (g < n):
        new_tree = jiashen(new_tree)
    le = len(d1)
    if (le <= n//2):
        print(le)
        print(' '.join([str(x+1) for x in d1]))
    else:
        print(n - le)
        print(' '.join([str(x+1) for x in d2]))

def jiashen(new_tree):
    nonlocal g
    nonlocal k
    js = []
    for i in new_tree:
        for j in gra[i]:
            if (fil[j]):
                fil[j] = 0
                js.append(j)
                g += 1
                if (k):
                    d2.append(j)
                else:
                    d1.append(j)
    k = False if k else True
    return js

t = int(input())
zong = []
for _ in range(t):
    n, m = map(int, input().split())
    gra = [[] for i in range(n)]
    d1 = [0]
    d2 = []
    fil = [1 for i in range(n)]
    fil[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        gra[a-1].append(b-1)
        gra[b-1].append(a-1)
    new_tree = [0]
    k = True
    g = 1
    while (g < n):
        new_tree = jiashen(new_tree)
    le = len(d1)
    if (le <= n//2):
        zong.append(str(le)+'\n'+' '.join([str(x+1) for x in d1]))
    else:
        zong.append(str(n-le)+'\n'+' '.join([str(x+1) for x in d2]))
print('\n'.join(zong))

import sys
input = sys.stdin.readline

def jiashen(new_tree):
    nonlocal g
    nonlocal k
    js = []
    for i in new_tree:
        for j in gra[i]:
            if (fil[j]):
                fil[j] = 0
                js.append(j)
                g += 1
                if (k):
                    d2.append(j)
                else:
                    d1.append(j)
    k = False if k else True
    return js

t = int(input())
zong = []
for _ in range(t):
    n, m = map(int, input().split())
    gra = [[] for i in range(n)]
    d1 = [0]
    d2 = []
    fil = [1 for i in range(n)]
    fil[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        gra[a-1].append(b-1)
        gra[b-1].append(a-1)
    new_tree = [0]
    k = True
    g = 1
    while (g < n):
        new_tree = jiashen(new_tree)
    le = len(d1)
    if (le <= n//2):
        zong.append(str(le)+'\n'+' '.join([str(x+1) for x in d1]))
    else:
        zong.append(str(n-le)+'\n'+' '.join([str(x+1) for x in d2]))
print('\n'.join(zong))

from collections import deque
import sys

def __starting_point():
    t = int(input())
    lns = sys.stdin.readlines()
    i = 0
    result = []
    for _ in range(t):
        n, m = map(int, lns[i].split())
        i += 1
        g = [[] for _ in range(n)]
        for _ in range(m):
            v, u = map(int, lns[i].split())
            i += 1
            g[v - 1].append(u - 1)
            g[u - 1].append(v - 1)

        q = deque()
        vis = [False] * n
        lvl = [-1] * n
        lvl[0] = 0
        vis[0] = True
        q.append(0)
        while len(q) > 0:
            v = q.popleft()
            for u in g[v]:
                if not vis[u]:
                    vis[u] = True
                    lvl[u] = lvl[v] + 1
                    q.append(u)

        odd = [str(i + 1) for i in range(n) if lvl[i] % 2 == 1]
        even = [str(i + 1) for i in range(n) if lvl[i] % 2 == 0]
        res = odd if len(odd) < len(even) else even
        result.append(str(len(res)))
        result.append(" ".join(res))

    print("\n".join(result))
__starting_point()

def jiashen(new_tree):
    nonlocal g
    nonlocal k
    js = []
    for i in new_tree:
        for j in gra[i]:
            if (fil[j]):
                fil[j] = 0
                js.append(j)
                g += 1
                if (k):
                    d2.append(j)
                else:
                    d1.append(j)
    k = False if k else True
    return js


t = int(input())
zong = []
for _ in range(t):
    n, m = map(int, input().split())
    gra = [[] for i in range(n)]
    d1 = [0]
    d2 = []
    fil = [1 for i in range(n)]
    fil[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        gra[a-1].append(b-1)
        gra[b-1].append(a-1)
    new_tree = [0]
    k = True
    g = 1
    while (g < n):
        new_tree = jiashen(new_tree)
    le = len(d1)
    if (le <= n//2):
        zong.append(str(le)+'\n'+' '.join([str(x+1) for x in d1]))
    else:
        zong.append(str(n-le)+'\n'+' '.join([str(x+1) for x in d2]))
print('\n'.join(zong))

import sys
from collections import deque 
for _ in range(int(input())):
    n,m=map(int,sys.stdin.readline().split())
    a=[[] for i in range(n+1)]
    for i in range(m):
        x,y=map(int,sys.stdin.readline().split())
        a[x].append(y)
        a[y].append(x)
    col=[-1]*(n+1)
    col[1]=1
    d=deque([1])
    vis=[0]*(n+1)
    # vis[1]=1
    ans=[[],[1]]
    
    while d:
        p=d.popleft()
        for i in a[p]:
            if col[i]==-1:
                col[i]=1-col[p]
                ans[1-col[p]].append(i)
                d.append(i)
    
    if len(ans[0])<=n//2:
        print(len(ans[0]))
        
        print(*ans[0])
    else:
        print(len(ans[1]))
        
        print(*ans[1])

import sys
from collections import deque
for case in range(int(input())):
    n, m = map(int, sys.stdin.readline().split()) #fast io
    g = [[] for i in range(n + 1)]
    for i in range(m):
        x, y = map(int, sys.stdin.readline().split())
        g[x].append(y)
        g[y].append(x)
    col = [-1] * (n + 1)
    col[1] = 1
    Q = deque() #calling deque data structure from collections
    Q.append(1)
    ans = [[] for i in range(2)]
    ans[1].append(1)
    while Q:
        From = Q.popleft()
        for To in g[From]:
            if(col[To] == -1):
                if col[From] == 1:
                    col[To] = 2
                else:
                    col[To] = 1
                ans[col[To] % 2].append(To)
                Q.append(To)

    if len(ans[0]) < len(ans[1]):
        print(len(ans[0]))
        print(*ans[0])
    else:
        print(len(ans[1]))
        print(*ans[1])

import sys
from collections import deque
for case in range(int(input())):
    n, m = map(int, sys.stdin.readline().split()) #fast io
    g = [[] for i in range(n + 1)]
    for i in range(m):
        x, y = map(int, sys.stdin.readline().split())
        g[x].append(y)
        g[y].append(x)
    col = [-1] * (n + 1)
    col[1] = 1
    Q = deque()
    Q.append(1)
    ans = [[] for i in range(2)]
    ans[1].append(1)
    while Q:
        From = Q.popleft()
        for To in g[From]:
            if(col[To] == -1):
                if col[From] == 1:
                    col[To] = 2
                else:
                    col[To] = 1
                ans[col[To] % 2].append(To)
                Q.append(To)

    if len(ans[0]) < len(ans[1]):
        print(len(ans[0]))
        #print(*ans[0])
        for each in ans[0]:
            print(each)
    else:
        print(len(ans[1]))
        for each in ans[1]:
            print(each)

import sys
from collections import deque
# wtfffffffffffff
for case in range(int(input())):
    n, m = map(int, sys.stdin.readline().split()) #fast io
    g = [[] for i in range(n + 1)]
    for i in range(m):
        x, y = map(int, sys.stdin.readline().split())
        g[x].append(y)
        g[y].append(x)
    col = [-1] * (n + 1)
    col[1] = 1
    Q = deque()
    Q.append(1)
    ans = [[] for i in range(2)]
    ans[1].append(1)
    while Q:
        From = Q.popleft()
        for To in g[From]:
            if(col[To] == -1):
                if col[From] == 1:
                    col[To] = 2
                else:
                    col[To] = 1
                ans[col[To] % 2].append(To)
                Q.append(To)
 
    if len(ans[0]) < len(ans[1]):
        print(len(ans[0]))
        #print(*ans[0])
        for each in ans[0]:
            print(each)
    else:
        print(len(ans[1]))
        for each in ans[1]:
            print(each)