#include<bits/stdc++.h>
using namespace std;
int vis[200007];
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>v[n+5];
    int a[n+5];
    memset(a,0,sizeof a);
    vector<pair<int,int> >vv,ans;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        a[x]++;
        a[y]++;
    }

    for(int i=1;i<=n;i++){
        vv.push_back({a[i],i});
    }
    sort(vv.rbegin(),vv.rend());
    int sum=0;
    for(int i=0;i<vv.size();i++){
        if(sum<n){
            int pos=vv[i].second;

            for(int j=0;j<v[pos].size();j++){
                if(sum>=n-1){
                    break;
                }
                if(vis[pos]==0){
                    vis[pos]=1;
                    //sum++;
                }
                if(vis[v[pos][j]]==0){
                    vis[v[pos][j]]=1;
                    ans.push_back({pos,v[pos][j]});
                    sum++;
                }
            }
        }
        else{
            break;
        }
    }
    for(int i=0;i<ans.size();i++)cout<<ans[i].first<<" "<<ans[i].second<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int vis[200007];
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>v[n+5];
    int a[n+5];
    memset(a,0,sizeof a);
    vector<pair<int,int> >vv,ans;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        a[x]++;
        a[y]++;
    }

    for(int i=1;i<=n;i++){
        vv.push_back({a[i],i});
    }
    sort(vv.rbegin(),vv.rend());
    int src=vv[0].second;
    queue<int>q;
    q.push(src);
    vis[src]=1;
    while(!q.empty())
    {
        int top=q.front();
        q.pop();
        for(int i=0;i<v[top].size();i++){
            if(vis[v[top][i]]==0){
                q.push(v[top][i]);
                vis[v[top][i]]=1;
                ans.push_back({top,v[top][i]});
            }
        }
    }
    for(int i=0;i<min(n-1,(int)ans.size());i++)cout<<ans[i].first<<" "<<ans[i].second<<endl;
}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=2e5+10;
vector<vector<LL>>G(N),g(N);
priority_queue<pair<LL,LL>>q;
vector<bool>C(N,true);
map<pair<LL,LL>,LL>M;
//vector<LL>A(N),C(N);
LL d,n,m;

void dfs(LL I)
{
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(C[ G[I][i] ]==true )
		{
			if(!M[{I,G[I][i]}] && !M[{G[I][i],I}])g[I].push_back(	G[I][i]);
			C[G[I][i]]=false;
		}
	}
}

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for(LL i=1;i<=n;i++)
	q.push({G[i].size(),i});

	C[q.top().second]=false;
	while(q.size())
	{
		dfs(q.top().second);q.pop();
	}

	for(LL i=1;i<=n;i++)
	{
		for(LL j=0;j<(LL)g[i].size();j++)
		cout<<i<<" "<<g[i][j]<<endl;
	}

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e5+10;
vector<vector<LL>>G(N),g(N);
priority_queue<pair<LL,LL>>q;
vector<bool>C(N,true);
map<pair<LL,LL>,LL>M;
//vector<LL>A(N),C(N);
LL d,n,m;

void dfs(LL I)
{
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(C[ G[I][i] ]==true )
		{
			if(!M[{I,G[I][i]}] && !M[{G[I][i],I}])g[I].push_back(	G[I][i]);
			C[G[I][i]]=false;
		}
	}
}

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for(LL i=1;i<=n;i++)
	q.push({G[i].size(),i});

	C[q.top().second]=true;
	while(q.size())
	{
		dfs(q.top().second);q.pop();
	}

	for(LL i=1;i<=n;i++)
	{
		for(LL j=0;j<(LL)g[i].size();j++)
		cout<<i<<" "<<g[i][j]<<endl;
	}

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e5+10;
vector<vector<LL>>G(N),g(N);
priority_queue<pair<LL,LL>>q;
vector<bool>C(N,true);
map<pair<LL,LL>,LL>M;
//vector<LL>A(N),C(N);
LL d,n,m;

void dfs(LL I)
{
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(C[ G[I][i] ]==true )
		{
			if(!M[{I,G[I][i]}] && !M[{G[I][i],I}])g[I].push_back(	G[I][i]);
			C[G[I][i]]=false;
		}
	}
}

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for(LL i=1;i<=n;i++)
	q.push({G[i].size(),i});

	C[q.top().second]=false;
	while(q.size())
	{
		dfs(q.top().second);q.pop();
	}

	for(LL i=1;i<=n;i++)
	{
		for(LL j=0;j<(LL)g[i].size();j++)
		cout<<i<<" "<<g[i][j]<<endl;
	}

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=2e5+10;
vector<vector<LL>>G(N);

priority_queue<pair<LL,LL>>q;

vector<pair<LL,LL>>A;
vector<bool>B(N);
LL d,n,m;

/*
void dfs(LL I)
{
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(B[ G[I][i] ]==false )
		{
			   cout<<"FS:"<<I<<" "<<G[I][i]<<endl;
				M[{max(I,G[I][i]),min(I,G[I][i])}]++;
		}
	}
}*/

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	LL I=0,mx=0;
	for(LL i=1;i<=n;i++)
	{
		if(mx<(LL)G[i].size())
		{
			mx=G[i].size();
			I=i;
		}
	}

	q.push({G[I].size(),I});
	B[I]=true;

	while(q.size())
	{
		LL p=q.top().second;
		q.pop();
		for(LL i=0;i<(LL)G[p].size();i++)
		{
			if(B[ G[p][i] ]==false)
			{
				A.push_back({p,G[p][i]});
				q.push({G[  G[p][i] ].size(),G[p][i]});
				B[  G[p][i] ]=true;
			}
		}
	}

	for(LL i=0;i<(LL)A.size();i++)
	cout<<A[i].first<<" "<<A[i].second<<endl;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e5+10;
vector<vector<LL>>G(N),g(N);
vector<bool>B(N,true);
//vector<LL>A(N),C(N);
LL d,n,m;

void dfs(LL I)
{
	B[I]=false;
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(B[G[I][i]])
		{
			g[I].push_back(	G[I][i]);
			dfs(G[I][i]);
		}
	}
}

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	dfs(1);

	for(LL i=1;i<=n;i++)
	{
		for(LL j=0;j<(LL)g[i].size();j++)
		cout<<i<<" "<<g[i][j]<<endl;
	}

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=2e5+10;
vector<vector<LL>>G(N),g(N);
priority_queue<pair<LL,LL>>q;
map<pair<LL,LL>,LL>M;
vector<bool>B(N);
LL d,n,m;

void dfs(LL I)
{
	for(LL i=0;i<(LL)G[I].size();i++)
	{
		if(B[ G[I][i] ]==false && !M[{I,G[I][i]}])
		{
				g[I].push_back(	G[I][i]);
				M[{I,G[I][i]}]++;
				M[{G[I][i],I}]++;
				B[ G[I][i] ]=true;
		}
	}
}

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for(LL i=1;i<=n;i++)
	q.push({G[i].size(),i});

	while(q.size())
	{
		dfs(q.top().second);q.pop();
	}

	for(LL i=1;i<=n;i++)
	{
		for(LL j=0;j<(LL)g[i].size();j++)
		cout<<i<<" "<<g[i][j]<<endl;
	}

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define LD long double
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const LL N=2e5+10;
vector<vector<LL>>G(N);
vector<bool>B(N);
LL n,m;

int main()
{
	IOS
	cin>>n>>m;
	for(LL i=0;i<m;i++)
	{
		LL x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	LL I=0,mx=0;
	for(LL i=1;i<=n;i++)
	if((LL)G[i].size()>mx)
	{
		mx=G[i].size();
		I=i;
	}

	queue<LL>q;
	vector<pair<LL,LL>>A;
	q.push(I);
	B[I]=true;
	while(q.size())
	{
		LL p=q.front();q.pop();
		for(LL i=0;i<(LL)G[p].size();i++)
		if(B[ G[p][i] ]==false)
		{
			A.push_back({p,G[p][i]});
			q.push(G[p][i]);
			B[ G[p][i] ]=true;
		}
	}

	for(LL i=0;i<(LL)A.size();i++)
	cout<<A[i].first<<" "<<A[i].second<<endl;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];

void solve( int src){
	queue <int>q;
	q.push(src);
	while (!q.empty()){
	int top = q.front() ;
	q.pop();
	vis[top] = true ;
	for (int  nei : edges[top])
	{
		if (!vis[nei])
		 {	q.push(nei);
			 res[top].pb(nei);
		}

	}

	}

}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });
int top =pq.top().ss;
solve(top);
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];
int p[M];
void init (){
	for(int i = 0 ;i < M ; ++ i )
	p[i] = i ;
}
int par(int x )
{
	return (x == p[x] ? x : p[x] = par(p[x]));
}
bool merge(int  x ,  int y ){
	int px = p[x];
	int py = p[y];
	if (px != py )
	{
	p[py] = p[px];
	return true ;
	}
	return false ;

}

void solve( int src){
for (int nei:edges[src] )
{
	bool ok = merge(src , nei );
	if (ok)
	res[src].pb(nei),
	vis[nei] = true ;

}
vis[src] = true ;
}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
init();
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });

while (!pq.empty()){
 int top = pq.top().ss ;
  pq.pop();
  solve(top);

}
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];
int p[M];
void init (){
	for(int i = 0 ;i < M ; ++ i )
	p[i] = i ;
}
int par(int x )
{
	return (x == p[x] ? x : p[x] = par(p[x]));
}
bool merge(int  x ,  int y ){
	int px = p[x];
	int py = p[y];
	if (px!= py )
	{
	p[py] = p[px];
	return true ;
	}
	return false ;

}

void solve( int src){
for (int nei:edges[src] )
{
		bool ok = merge(src , nei );
		if (ok) {
		res[src].pb(nei);
		vis[nei] = true ;
		}
}

}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
init();
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });

while (!pq.empty()){
 int top = pq.top().ss ;
  pq.pop();

  solve(top);

}
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];

void solve( int src){
	queue <int>q;
	q.push(src);
	vis[src] = true ;
	while (!q.empty()){
	int top = q.front() ;
	q.pop();
	for (int  nei : edges[top])
	{
		if (!vis[nei])
		 {	q.push(nei);
			res[top].pb(nei);
			vis[nei] = true ;
		}

	}

	}

}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });
int top =pq.top().ss;
solve(top);
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];
int p[M];
void init (){
	for(int i = 0 ;i < M ; ++ i )
	p[i] = i ;
}
int par(int x )
{
	return (x == p[x] ? x : p[x] = par(p[x]));
}
bool merge(int  x ,  int y ){
	int px = p[x];
	int py = p[y];
	if (px!= py )
	{
	p[py] = p[px];
	return true ;
	}
	return false ;

}

void solve( int src){
for (int nei:edges[src] )
{	bool ok = false ;
	if (!vis[nei] )
		 ok = merge(src , nei );
		if (ok) {
		res[src].pb(nei);
		vis[nei] = true ;
		}
}

}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
init();
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });

while (!pq.empty()){
 int top = pq.top().ss ;
  pq.pop();
  solve(top);

}
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
// #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
vector<int>edges[M];
vector<int>res[M];

bool vis[M];
int p[M];
void init (){
	for(int i = 0 ;i < M ; ++ i )
	p[i] = i ;
}
int par(int x )
{
	return (x == p[x] ? x : p[x] = par(p[x]));
}
bool merge(int  x ,  int y ){
	int px = p[x];
	int py = p[y];
	if (px != py )
	{
	p[py] = p[px];
	return true ;
	}
	return false ;

}

void solve( int src){
for (int nei:edges[src] )
{	if (!vis[nei] ){
		bool ok = merge(src , nei );
	if (ok)
	res[src].pb(nei),
	vis[nei] = true ;
	}
}

}

int main ( ){
fast_io();
int n , m ;
cin >> n >> m ;
init();
for (int i = 0 ; i < m ; ++ i )
{
	int u , v ;
	cin >> u >>v ;
	--u,--v;
	edges[u].pb(v);
	edges[v].pb(u);

}

priority_queue<pair<int , int >>pq ;
for (int i = 0 ; i < n ; ++ i )
	pq.push({edges[i].size() , i });

while (!pq.empty()){
 int top = pq.top().ss ;
  pq.pop();
  solve(top);

}
for (int i = 0 ; i < n; ++ i )
 {
	 // cout << i+1 <<" : ";
	for(int j = 0 ; j < (int)res[i].size() ; ++j  )
		cout << i+1 << " " << res[i][j]+1,br

 }

return 0 ;

}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include <cstdlib>
#include <climits>
#include <iomanip>
#include<iostream>
#include <sstream>  // for string streams
#include <string>  // for string
#include <stack>
#include <cmath>

#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")

#define ll long long
#define ld long double
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define fn(a,n) for(ll a=0; a<n; a++)
#define flr(a,l,r) for(ll a=l; a<=r;a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) for (ll i = 0; i < a; i++) for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));

//#define p(n) cout<<n<<"\n";
#define MOD 1000000007

using namespace std;

void print_width(ll x) {

    std::cout << std::fixed;
    std::cout << std::setprecision(x);
}

ll power(ll x, ll y, ll p = MOD)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

void printArr(ll a[], ll n) {
    f(n)
        cout << a[i] << " ";
    cout << endl;
}

void printVector(std::vector<ll> v) {
    f(v.size())
        cout << v[i] << " ";
    cout << endl;
}

void printVectorPair(std::vector<pair<ll, ll>> v) {
    f(v.size())
        pp2(v[i].first, v[i].second);
    cout << endl;
}

ll Min(ll a, ll b, ll c) {
    if (a < b and a < c)
        return a;
    if (b < c)
        return b;
    return c;
}

void initialize(ll arr[], ll n) {
    for (ll i = 0; i <= n; i++)
        arr[i] = i;
}

ll root(ll arr[], ll i) {

    while (arr[i] != i) {
        arr[ i ] = arr[ arr[ i ] ] ;
        i = arr[i];
    }
    return i;

}

void Union(ll arr[], ll a, ll b) {
    ll root_a = root(arr, a);
    ll root_b = root(arr, b);

    arr[root_a] = root_b;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else return gcd(b, a % b);
}

ll power_wm(ll x, ll y)
{
    ll res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

long double dpower(long double x, ll y) {
    long double res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

std::vector<ll> vsum(std::vector<ll> a) {

    std::vector<ll> s(a.size());
    s[0] = a[0];
    flr (i, 1, a.size() - 1) {
        s[i] = s[i - 1] + a[i];
    }
    return s;
}

bool comp( pair<ll, ll> a, pair<ll, ll> b) {
    ll x = a.second * b.first;
    ll y = a.first * b.second;

    if (x <= y)
        return false;
    else
        return true;
}

bool is_cap(char a) {

    if (a <= 'Z' and a >= 'A')
        return true;
    else
        return false;
}

bool is_small(char a) {

    if (a <= 'z' and a >= 'a')
        return true;
    else
        return false;
}

string findSum(string str1, string str2)
{
    string str = "";
    if (str1.size() > str2.size())  {
        swap(str1, str2);
    }

    int n1 = str1.size(), n2 = str2.size();

    reverse(all(str1));
    reverse(all(str2));

    int carry;
    carry = 0;
    for (int i = 0; i<n1; i++) {
        int sum;
        sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.pb(sum%10 + '0');

        carry = sum / 10;
    }

    for (int i=n1; i<n2; i++)  {
        int sum;
        sum = ((str2[i]-'0')+carry);
        str.pb(sum%10 + '0');
        carry = sum/10;
    }

    if (carry)
        str.pb(carry+'0');

    reverse(all(str));

    return str;
}

bool mcomp(ll a, ll b, ll c, ll d) {

    if (a == b and b == c and c == d)
        return true;
    else
        return false;

}

// vector<vector<pair<ll, ll>>> adj;
// void dijikstra(int s, vector<ll> & d, vector<ll> & p) {

//     ll n = adj.size();
//     d.assign(n, inf);
//     p.assign(n, -1);

//     d[s] = 0;
//     set<pair<ll, ll>> q;
//     q.insert({0, s});

//     while (!q.empty()) {

//         ll v = q.begin() -> second;
//         q.erase(q.begin());

//         for (auto edge: adj[v]) {

//             ll to = edge.first;
//             ll len = edge.second;

//             if (d[v] + len < d[to]) {
//                 q.erase({d[to], to});
//                 d[to] = d[v] + len;
//                 p[to] = v;
//                 q.insert({d[to], to});
//             }

//         }

//     }

// }

// graph(200000);
// ll dfs(ll x, vec &vis, vec &dfs_seq, vec &children) {

//     dfs_seq.pb(x);
//     for (ll i = 0; i < g[x].size(); i++) {

//         ll y = g[x][i];
//         if (vis[y] == 0) {
//             vis[y] = 1;
//             dfs(y, vis, dfs_seq, children);
//             children[x] += 1 + children[y];
//         }
//     }
//     return 0;
// }

ll c2(ll n) {
    return (n * (n - 1)) / 2;
}

int main() {

    //Using text files for input output
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //FastIO
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // start your code here
    // print_width(15);

    ll n, m;

    cin >> n >> m;

    vec vis(n + 1, 0);

    ll ec = 0;
    ll nc = 0;

    vp edge;

    f(m) {
        ll a, b;
        cin >> a >> b;

        ll tn = nc;

        if (vis[a] == 0)
            tn++;
        if (vis[b] == 0)
            tn++;

        if (tn > (ec + 1)) {

            if (vis[a] == 0)
                nc++;
            if (vis[b] == 0)
                nc++;

            vis[a] = 1;
            vis[b] = 1;
            edge.pb(mp(a, b));
            ec++;
        }

    }

    printVectorPair(edge);

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include <cstdlib>
#include <climits>
#include <iomanip>
#include<iostream>
#include <sstream>  // for string streams
#include <string>  // for string
#include <stack>
#include <cmath>

#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")

#define ll long long
#define ld long double
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define fn(a,n) for(ll a=0; a<n; a++)
#define flr(a,l,r) for(ll a=l; a<=r;a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) for (ll i = 0; i < a; i++) for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));

//#define p(n) cout<<n<<"\n";
#define MOD 1000000007

using namespace std;

void print_width(ll x) {

    std::cout << std::fixed;
    std::cout << std::setprecision(x);
}

ll power(ll x, ll y, ll p = MOD)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

void printArr(ll a[], ll n) {
    f(n)
        cout << a[i] << " ";
    cout << endl;
}

void printVector(std::vector<ll> v) {
    f(v.size())
        cout << v[i] << " ";
    cout << endl;
}

void printVectorPair(std::vector<pair<ll, ll>> v) {
    f(v.size())
        pp2(v[i].first, v[i].second);
    cout << endl;
}

ll Min(ll a, ll b, ll c) {
    if (a < b and a < c)
        return a;
    if (b < c)
        return b;
    return c;
}

void initialize(ll arr[], ll n) {
    for (ll i = 0; i <= n; i++)
        arr[i] = i;
}

ll root(ll arr[], ll i) {

    while (arr[i] != i) {
        arr[ i ] = arr[ arr[ i ] ] ;
        i = arr[i];
    }
    return i;

}

void Union(ll arr[], ll a, ll b) {
    ll root_a = root(arr, a);
    ll root_b = root(arr, b);

    arr[root_a] = root_b;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else return gcd(b, a % b);
}

ll power_wm(ll x, ll y)
{
    ll res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

long double dpower(long double x, ll y) {
    long double res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

std::vector<ll> vsum(std::vector<ll> a) {

    std::vector<ll> s(a.size());
    s[0] = a[0];
    flr (i, 1, a.size() - 1) {
        s[i] = s[i - 1] + a[i];
    }
    return s;
}

bool comp( pair<ll, ll> a, pair<ll, ll> b) {
    ll x = a.second * b.first;
    ll y = a.first * b.second;

    if (x <= y)
        return false;
    else
        return true;
}

bool is_cap(char a) {

    if (a <= 'Z' and a >= 'A')
        return true;
    else
        return false;
}

bool is_small(char a) {

    if (a <= 'z' and a >= 'a')
        return true;
    else
        return false;
}

string findSum(string str1, string str2)
{
    string str = "";
    if (str1.size() > str2.size())  {
        swap(str1, str2);
    }

    int n1 = str1.size(), n2 = str2.size();

    reverse(all(str1));
    reverse(all(str2));

    int carry;
    carry = 0;
    for (int i = 0; i<n1; i++) {
        int sum;
        sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.pb(sum%10 + '0');

        carry = sum / 10;
    }

    for (int i=n1; i<n2; i++)  {
        int sum;
        sum = ((str2[i]-'0')+carry);
        str.pb(sum%10 + '0');
        carry = sum/10;
    }

    if (carry)
        str.pb(carry+'0');

    reverse(all(str));

    return str;
}

bool mcomp(ll a, ll b, ll c, ll d) {

    if (a == b and b == c and c == d)
        return true;
    else
        return false;

}

// vector<vector<pair<ll, ll>>> adj;
// void dijikstra(int s, vector<ll> & d, vector<ll> & p) {

//     ll n = adj.size();
//     d.assign(n, inf);
//     p.assign(n, -1);

//     d[s] = 0;
//     set<pair<ll, ll>> q;
//     q.insert({0, s});

//     while (!q.empty()) {

//         ll v = q.begin() -> second;
//         q.erase(q.begin());

//         for (auto edge: adj[v]) {

//             ll to = edge.first;
//             ll len = edge.second;

//             if (d[v] + len < d[to]) {
//                 q.erase({d[to], to});
//                 d[to] = d[v] + len;
//                 p[to] = v;
//                 q.insert({d[to], to});
//             }

//         }

//     }

// }

// graph(200000);
// ll dfs(ll x, vec &vis, vec &dfs_seq, vec &children) {

//     dfs_seq.pb(x);
//     for (ll i = 0; i < g[x].size(); i++) {

//         ll y = g[x][i];
//         if (vis[y] == 0) {
//             vis[y] = 1;
//             dfs(y, vis, dfs_seq, children);
//             children[x] += 1 + children[y];
//         }
//     }
//     return 0;
// }

ll c2(ll n) {
    return (n * (n - 1)) / 2;
}

int main() {

    //Using text files for input output
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //FastIO
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // start your code here
    // print_width(15);

    ll n, m;

    cin >> n >> m;

    graph(n);
    vec deg(n + 1, 0);

    f (m) {
        ll a, b;
        cin >> a >> b;

        g[a].pb(b);
        g[b].pb(a);
        deg[a]++;
        deg[b]++;

    }

    ll pos = 1;

    flr (i, 1, n)
        if (deg[i] > deg[pos])
            pos = i;

    queue<ll> q;
    q.push(pos);
    vec vis(n + 1, 0);

    vis[pos] = 1;

    while (!q.empty()) {

        ll x = q.front();
        q.pop();

        for (ll i = 0; i < g[x].size(); i++) {

            ll y = g[x][i];
            if (vis[y] == 0) {

                pp2(x, y);
                vis[y] = 1;
                q.push(y);

            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define inf (int)1e9
#define f(n) for(ll i=0;i<n;i++)
#define fn(a,n) for(ll a=0; a<n; a++)
#define flr(a,l,r) for(ll a=l; a<=r;a++)
#define mp make_pair
#define vec vector<ll>
#define vp vector<pair<ll, ll>>
#define vv vector<vector<ll>>
#define graph(n) vector<vector<ll>> g(n + 1)
#define sorta(a) sort(a.begin(), a.end())
#define sortd(a) sort(a.begin(), a.end(), greater<ll>())
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>())
#define lb(a, x) (lower_bound(a.begin(), a.end(), x) - a.begin())
#define ub(a, x) (upper_bound(a.begin(), a.end(), x) - a.begin())
#define endl '\n'

//#define p(n) cout<<n<<"\n";

#define MOD 1000000007

using namespace std;

//custom functions

ll power_wm(ll x, ll y) {
    ll res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x);

        y = y >> 1;
        x = (x * x);
    }
    return res;
}

ll power(ll x, ll y, ll p = MOD) {
    ll res = 1;
    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

void print_vector(vec a) {
    for (ll i = 0; i < a.size(); i++)
        cout << a[i] << " ";
    cout << endl;
}

void initialize(vec &arr, ll n) {
    for (ll i = 0; i <= n; i++)
        arr[i] = i;
}

ll root(vec &arr, ll i) {

    while (arr[i] != i) {
        arr[i] = arr[arr[i]] ;
        i = arr[i];
    }
    return i;

}

void Union(vec &arr, ll a, ll b) {
    ll root_a = root(arr, a);
    ll root_b = root(arr, b);

    arr[root_a] = root_b;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else return gcd(b, a % b);
}

//custom functions end

int main() {

    //Using text files for input output
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //FastIO
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // start your code here4 6
    ll n, m;
    cin >> n >> m;
    graph(n);
    vec deg(n);

    f (m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].pb(b);
        g[b].pb(a);
        deg[a]++;
        deg[b]++;
    }

    vp edges;
    ll max_deg = -1;
    ll node = -1;
    vec dsu(n + 1);

    for (ll i = 0; i < n; i++) {
        if (max_deg < deg[i]) {
            max_deg = deg[i];
            node = i;
        }
    }

    initialize(dsu, n);
    for (ll i = 0; i < g[node].size(); i++) {
        ll y = g[node][i];
        Union(dsu, node, y);
        edges.pb(mp(node, y));
    }

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < g[i].size(); j++) {
            ll a = i;
            ll b = g[i][j];

            if (root(dsu, a) != root(dsu, b)) {
                Union(dsu, a, b);
                edges.pb(mp(a, b));
            }
        }
    }

    // cout << edges.size() << endl;
    f (edges.size()) {
        cout << edges[i].first + 1 << " " << edges[i].second + 1 << endl;
    }

}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include <cstdlib>
#include <climits>
#include <iomanip>
#include<iostream>
#include <sstream>  // for string streams
#include <string>  // for string
#include <stack>
#include <cmath>

#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")

#define ll long long
#define ld long double
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define fn(a,n) for(ll a=0; a<n; a++)
#define flr(a,l,r) for(ll a=l; a<=r;a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) for (ll i = 0; i < a; i++) for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));

//#define p(n) cout<<n<<"\n";
#define MOD 1000000007

using namespace std;

void print_width(ll x) {

    std::cout << std::fixed;
    std::cout << std::setprecision(x);
}

ll power(ll x, ll y, ll p = MOD)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

void printArr(ll a[], ll n) {
    f(n)
        cout << a[i] << " ";
    cout << endl;
}

void printVector(std::vector<ll> v) {
    f(v.size())
        cout << v[i] << " ";
    cout << endl;
}

void printVectorPair(std::vector<pair<ll, ll>> v) {
    f(v.size())
        pp2(v[i].first, v[i].second);
    cout << endl;
}

ll Min(ll a, ll b, ll c) {
    if (a < b and a < c)
        return a;
    if (b < c)
        return b;
    return c;
}

void initialize(ll arr[], ll n) {
    for (ll i = 0; i <= n; i++)
        arr[i] = i;
}

ll root(ll arr[], ll i) {

    while (arr[i] != i) {
        arr[ i ] = arr[ arr[ i ] ] ;
        i = arr[i];
    }
    return i;

}

void Union(ll arr[], ll a, ll b) {
    ll root_a = root(arr, a);
    ll root_b = root(arr, b);

    arr[root_a] = root_b;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else return gcd(b, a % b);
}

ll power_wm(ll x, ll y)
{
    ll res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

long double dpower(long double x, ll y) {
    long double res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

std::vector<ll> vsum(std::vector<ll> a) {

    std::vector<ll> s(a.size());
    s[0] = a[0];
    flr (i, 1, a.size() - 1) {
        s[i] = s[i - 1] + a[i];
    }
    return s;
}

bool comp( pair<ll, ll> a, pair<ll, ll> b) {
    ll x = a.second * b.first;
    ll y = a.first * b.second;

    if (x <= y)
        return false;
    else
        return true;
}

bool is_cap(char a) {

    if (a <= 'Z' and a >= 'A')
        return true;
    else
        return false;
}

bool is_small(char a) {

    if (a <= 'z' and a >= 'a')
        return true;
    else
        return false;
}

string findSum(string str1, string str2)
{
    string str = "";
    if (str1.size() > str2.size())  {
        swap(str1, str2);
    }

    int n1 = str1.size(), n2 = str2.size();

    reverse(all(str1));
    reverse(all(str2));

    int carry;
    carry = 0;
    for (int i = 0; i<n1; i++) {
        int sum;
        sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.pb(sum%10 + '0');

        carry = sum / 10;
    }

    for (int i=n1; i<n2; i++)  {
        int sum;
        sum = ((str2[i]-'0')+carry);
        str.pb(sum%10 + '0');
        carry = sum/10;
    }

    if (carry)
        str.pb(carry+'0');

    reverse(all(str));

    return str;
}

bool mcomp(ll a, ll b, ll c, ll d) {

    if (a == b and b == c and c == d)
        return true;
    else
        return false;

}

// vector<vector<pair<ll, ll>>> adj;
// void dijikstra(int s, vector<ll> & d, vector<ll> & p) {

//     ll n = adj.size();
//     d.assign(n, inf);
//     p.assign(n, -1);

//     d[s] = 0;
//     set<pair<ll, ll>> q;
//     q.insert({0, s});

//     while (!q.empty()) {

//         ll v = q.begin() -> second;
//         q.erase(q.begin());

//         for (auto edge: adj[v]) {

//             ll to = edge.first;
//             ll len = edge.second;

//             if (d[v] + len < d[to]) {
//                 q.erase({d[to], to});
//                 d[to] = d[v] + len;
//                 p[to] = v;
//                 q.insert({d[to], to});
//             }

//         }

//     }

// }

// graph(200000);
// ll dfs(ll x, vec &vis, vec &dfs_seq, vec &children) {

//     dfs_seq.pb(x);
//     for (ll i = 0; i < g[x].size(); i++) {

//         ll y = g[x][i];
//         if (vis[y] == 0) {
//             vis[y] = 1;
//             dfs(y, vis, dfs_seq, children);
//             children[x] += 1 + children[y];
//         }
//     }
//     return 0;
// }

ll c2(ll n) {
    return (n * (n - 1)) / 2;
}

int main() {

    //Using text files for input output
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //FastIO
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // start your code here
    // print_width(15);

    ll n, m;

    cin >> n >> m;

    vec vis(n + 1, 0);

    vp edge;

    f(m) {
        ll a, b;
        cin >> a >> b;

        if (vis[a] == 1 and vis[b] == 1) {

        }
        else {
            edge.pb(mp(a, b));
            vis[a] = 1;
            vis[b] = 1;
        }
    }

    printVectorPair(edge);

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include <cstdlib>
#include <climits>
#include <iomanip>
#include<iostream>
#include <sstream>  // for string streams
#include <string>  // for string
#include <stack>
#include <cmath>

#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")

#define ll long long
#define ld long double
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define fn(a,n) for(ll a=0; a<n; a++)
#define flr(a,l,r) for(ll a=l; a<=r;a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) for (ll i = 0; i < a; i++) for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));

//#define p(n) cout<<n<<"\n";
#define MOD 1000000007

using namespace std;

void print_width(ll x) {

    std::cout << std::fixed;
    std::cout << std::setprecision(x);
}

ll power(ll x, ll y, ll p = MOD)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

void printArr(ll a[], ll n) {
    f(n)
        cout << a[i] << " ";
    cout << endl;
}

void printVector(std::vector<ll> v) {
    f(v.size())
        cout << v[i] << " ";
    cout << endl;
}

void printVectorPair(std::vector<pair<ll, ll>> v) {
    f(v.size())
        pp2(v[i].first, v[i].second);
    cout << endl;
}

ll Min(ll a, ll b, ll c) {
    if (a < b and a < c)
        return a;
    if (b < c)
        return b;
    return c;
}

void initialize(ll arr[], ll n) {
    for (ll i = 0; i <= n; i++)
        arr[i] = i;
}

ll root(ll arr[], ll i) {

    while (arr[i] != i) {
        arr[ i ] = arr[ arr[ i ] ] ;
        i = arr[i];
    }
    return i;

}

void Union(ll arr[], ll a, ll b) {
    ll root_a = root(arr, a);
    ll root_b = root(arr, b);

    arr[root_a] = root_b;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else return gcd(b, a % b);
}

ll power_wm(ll x, ll y)
{
    ll res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

long double dpower(long double x, ll y) {
    long double res = 1;      // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x);

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x);
    }
    return res;
}

std::vector<ll> vsum(std::vector<ll> a) {

    std::vector<ll> s(a.size());
    s[0] = a[0];
    flr (i, 1, a.size() - 1) {
        s[i] = s[i - 1] + a[i];
    }
    return s;
}

bool comp( pair<ll, ll> a, pair<ll, ll> b) {
    ll x = a.second * b.first;
    ll y = a.first * b.second;

    if (x <= y)
        return false;
    else
        return true;
}

bool is_cap(char a) {

    if (a <= 'Z' and a >= 'A')
        return true;
    else
        return false;
}

bool is_small(char a) {

    if (a <= 'z' and a >= 'a')
        return true;
    else
        return false;
}

string findSum(string str1, string str2)
{
    string str = "";
    if (str1.size() > str2.size())  {
        swap(str1, str2);
    }

    int n1 = str1.size(), n2 = str2.size();

    reverse(all(str1));
    reverse(all(str2));

    int carry;
    carry = 0;
    for (int i = 0; i<n1; i++) {
        int sum;
        sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.pb(sum%10 + '0');

        carry = sum / 10;
    }

    for (int i=n1; i<n2; i++)  {
        int sum;
        sum = ((str2[i]-'0')+carry);
        str.pb(sum%10 + '0');
        carry = sum/10;
    }

    if (carry)
        str.pb(carry+'0');

    reverse(all(str));

    return str;
}

bool mcomp(ll a, ll b, ll c, ll d) {

    if (a == b and b == c and c == d)
        return true;
    else
        return false;

}

// vector<vector<pair<ll, ll>>> adj;
// void dijikstra(int s, vector<ll> & d, vector<ll> & p) {

//     ll n = adj.size();
//     d.assign(n, inf);
//     p.assign(n, -1);

//     d[s] = 0;
//     set<pair<ll, ll>> q;
//     q.insert({0, s});

//     while (!q.empty()) {

//         ll v = q.begin() -> second;
//         q.erase(q.begin());

//         for (auto edge: adj[v]) {

//             ll to = edge.first;
//             ll len = edge.second;

//             if (d[v] + len < d[to]) {
//                 q.erase({d[to], to});
//                 d[to] = d[v] + len;
//                 p[to] = v;
//                 q.insert({d[to], to});
//             }

//         }

//     }

// }

// graph(200000);
// ll dfs(ll x, vec &vis, vec &dfs_seq, vec &children) {

//     dfs_seq.pb(x);
//     for (ll i = 0; i < g[x].size(); i++) {

//         ll y = g[x][i];
//         if (vis[y] == 0) {
//             vis[y] = 1;
//             dfs(y, vis, dfs_seq, children);
//             children[x] += 1 + children[y];
//         }
//     }
//     return 0;
// }

ll c2(ll n) {
    return (n * (n - 1)) / 2;
}

int main() {

    //Using text files for input output
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //FastIO
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // start your code here
    // print_width(15);

    ll n, m;

    cin >> n >> m;

    vec vis(n + 1, 0);

    ll ec = 0;
    ll nc = 0;

    vp edge;

    f(m) {
        ll a, b;
        cin >> a >> b;

        if (vis[a] == 0)
            nc++;
        if (vis[b] == 0)
            nc++;

        if (nc > (ec + 1)) {
            vis[a] = 1;
            vis[b] = 1;
            edge.pb(mp(a, b));
            ec++;
        }

    }

    printVectorPair(edge);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;
   for(int i=1;i<=n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   vis[start]=1;
   for(int i=0;i<v[start].size();i++)
    {
        cout<<start<<" "<<v[start][i]<<endl;
        vis[v[start][i]]=1;
    }
   for(int i=0;i<v[start].size();i++)
   {
            dfs(v[start][i]);
   }

}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;
   for(int i=1;i<n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   vis[start]=1;
   for(int i=0;i<v[start].size();i++)
    {
        cout<<start<<" "<<v[start][i]<<endl;
        vis[v[start][i]]=1;
    }
   for(int i=0;i<v[start].size();i++)
   {
            dfs(v[start][i]);
   }

}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;
   for(int i=1;i<n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   vis[start]=1;
   for(int i=0;i<v[start].size();i++)
    cout<<start<<" "<<v[start][i]<<endl;
   for(int i=0;i<=v[start].size();i++)
   {
        if(vis[i]==0)
            dfs(i);
   }

}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;
   for(int i=1;i<n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   vis[start]=1;
   for(int i=0;i<v[start].size();i++)
    {
        cout<<start<<" "<<v[start][i]<<endl;
        vis[v[start][i]]=1;
    }
   for(int i=0;i<=v[start].size();i++)
   {
            dfs(v[start][i]);
   }

}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;/////////
   for(int i=1;i<n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   vis[start]=1;
   for(int i=0;i<v[start].size();i++)
    {
        cout<<start<<" "<<v[start][i]<<endl;
        vis[v[start][i]]=1;
    }
   for(int i=0;i<=v[start].size();i++)
   {
            dfs(v[start][i]);
   }

}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000000];
int n,m1;
int vis[1000000];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(vis[v[x][i]]==0)
            {
                cout<<x<<" "<<v[x][i]<<endl;
                dfs(v[x][i]);
            }
    }
}
int main()
{
   cin>>n>>m1;
   int t=m1;
   while(t--)
   {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int start=1,m=0;
   for(int i=1;i<n;i++)
   {
    if(v[i].size()>m)
    {
        start=i;
        m=v[i].size();
    }
   }
   dfs(start);
   for(int i=1;i<=n;i++)
   {
        if(vis[i]==0)
            dfs(i);
   }

}


#include <iostream>
#include <vector>

using namespace std;

vector <int> g[200100];
bool used[200100];
int a[200100], b[200100];

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    int mast = 1;
    for (int i = 2; i <= n; i++)
        if (g[mast].size() < g[i].size())
            mast = i;
    for (int i = 0; i < g[mast].size(); i++){
        cout << mast << ' ' << g[mast][i] << '\n';
        used[i] = 1;
        used[g[mast][i]] = 1;
    }
    for (int i = 0; i < m; i++){
        if (used[a[i]] != used[b[i]]){
            cout << a[i] << ' ' << b[i] << '\n';
            used[a[i]] = 1;
            used[b[i]] = 1;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector <int> g[200100];
bool used[200100];
pair <int, int> a[200100];

bool cmp(pair <int, int> c, pair <int, int> d)
{
    int x = used[c.first] + used[c.second], y = used[d.second] + used[d.first];
    return x < y;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i].first >> a[i].second;
        g[a[i].first].push_back(a[i].second);
        g[a[i].second].push_back(a[i].first);
    }
    int mast = 1;
    for (int i = 2; i <= n; i++)
        if (g[mast].size() < g[i].size())
            mast = i;
    for (int i = 0; i < g[mast].size(); i++){
        cout << mast << ' ' << g[mast][i] << '\n';
        used[mast] = 1;
        used[g[mast][i]] = 1;
    }
    sort(a, a + m);
    for (int i = 0; i < m; i++){
        if (used[a[i].first] != used[a[i].second]){
            cout << a[i].first << ' ' << a[i].second << '\n';
            used[a[i].first] = 1;
            used[a[i].second] = 1;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector <int> g[200100];
bool used[200100];
int a[200100], b[200100];

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    int mast = 1;
    for (int i = 2; i <= n; i++)
        if (g[mast].size() < g[i].size())
            mast = i;
    for (int i = 0; i < g[mast].size(); i++){
        cout << mast << ' ' << g[mast][i] << '\n';
        used[mast] = 1;
        used[g[mast][i]] = 1;
    }
    for (int i = 0; i < m; i++){
        if (used[a[i]] != used[b[i]]){
            cout << a[i] << ' ' << b[i] << '\n';
            used[a[i]] = 1;
            used[b[i]] = 1;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector <int> g[200100], q;
bool used[200100];
pair <int, int> a[200100];
bool cmp(pair <int, int> c, pair <int, int> d)
{
    int x = used[c.first] + used[c.second], y = used[d.second] + used[d.first];
    return x < y;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i].first >> a[i].second;
        g[a[i].first].push_back(a[i].second);
        g[a[i].second].push_back(a[i].first);
    }
    int mast = 1;
    for (int i = 2; i <= n; i++)
        if (g[mast].size() < g[i].size())
            mast = i;
    for (int i = 0; i < g[mast].size(); i++){
        cout << mast << ' ' << g[mast][i] << '\n';
        used[mast] = 1;
        used[g[mast][i]] = 1;
        q.push_back(g[mast][i]);
    }
    while (!q.empty()){
        int v = q[0];
        for (int i = 0; i < g[v].size(); i++)
            if (!used[g[v][i]]){
                used[g[v][i]] = 1;
                q.push_back(g[v][i]);
                cout << v << ' ' << g[v][i] << '\n';
            }
        q.erase(q.begin());
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<u<<" "<<v<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(int i = 1 ; i <= n ; i++)
		for(auto it : vi[i])
			join(it , i);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<f<<" "<<s<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(auto it2 : vi[curr] )
		for(auto it : vi[it2])
			join(it , it2);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<f<<" "<<s<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(int i = 1 ; i <= n ; i++ )
		join(i , curr);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<u<<" "<<v<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(auto it2 : vi[curr] )
		for(auto it : vi[it2])
			join(it , it2);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<f<<" "<<s<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(int i = 1 ; i <= n ; i++ )
		for(auto it : vi[i])
			join(it , curr);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int  mxn = 2e5 + 5 , N = 8e1 + 5 , mod = 1e9 + 7 , inf = 0x3f , mod2 = 999119999 , mod3 = 1000992299 , pow1 = 31 , pow2 = 53 , Sqrt = 317 ;
void seif(){
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
}
int n , m , par[mxn] , in[mxn];
vector<int>vi[mxn];
int find_par(int node){
	return par[node] = par[node] == node ? node : find_par(par[node]);
}
void join(int u ,int v){
	int f = find_par(u) , s = find_par(v);
	if(f == s)return ;
	cout<<f<<" "<<s<<endl;
	par[s] = f;
	return;
}
int main(){
	//freopen("a.txt","rt" , stdin);
	//freopen("b.txt","w" , stdout);
	seif();
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	int curr = 1;
	for(int i = 1 ; i <= n ; i++){
		par[i] = i;
		if(in[i] > in[curr])
			 curr =i;
	}
	for(auto it : vi[curr])
		join(it ,  curr);
	for(int i = 1 ; i <= n ; i++ )
		for(auto it : vi[i])
			join(it , i);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,mx_cnt = -1,root,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    if(cnt[a]>mx_cnt){
      root = a;
      mx_cnt = cnt[a];
     }
    if(cnt[b]>mx_cnt)
      root = b;
      mx_cnt = cnt[b];
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,mx_cnt = 0,root,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    cnt[a]++;
    cnt[b]++;
    if(cnt[a]>mx_cnt){
      root = a;
      mx_cnt = cnt[a];
     }
    if(cnt[b]>mx_cnt)
      root = b;
      mx_cnt = cnt[b];
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,root = 0,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    cnt[a]++;
    cnt[b]++;
    if(cnt[a]>cnt[root]){
      root = a;
     }
    if(cnt[b]>cnt[root])
      root = b;
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,mx_cnt = 0,root,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    cnt[a]++;
    cnt[b]++;
    if(cnt[a]>mx_cnt){
      root = a;
      mx_cnt = cnt[a];
     }
    if(cnt[b]>mx_cnt){
      root = b;
      mx_cnt = cnt[b];
    }
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,root = 0,mx = -1,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    cnt[a]++;
    cnt[b]++;
    if(cnt[a]>mx){
      root = a;
      mx = cnt[a];
     }
    if(cnt[b]>mx){
      root = b;
      mx = cnt[b];
    }
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,mx_cnt = -1,root,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    if(cnt[a]>mx_cnt)
      root = a;
    if(cnt[b]>mx_cnt)
      root = b;
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int long long
#define ld long double
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define pii pair<long long,long long>
#define umap unordered_map<ll,ll>
#define prq priority_queue<int>
#define inf 1e12
#define test cout<<"abcd\n";
#define show1(x) cout<<x<<"\n"
#define show2(x,y) cout<<x<<" "<<y<<"\n"
#define show3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define endl "\n"
#define mod (int)1000000007
#define N (int)2e5+5
int32_t main(){
	fast;
  int n,m,a,b,mx_cnt = -1,root,temp;
  cin>>n>>m;
  vector<int>adj[n+5],cnt(n+5),vis(n+5);
   for(int i=1;i<=m;i++){
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
    cnt[a]++;
    cnt[b]++;
    if(cnt[a]>mx_cnt){
      root = a;
      mx_cnt = cnt[a];
     }
    if(cnt[b]>mx_cnt)
      root = b;
      mx_cnt = cnt[b];
   }
   queue<int>q;
   q.push(root);
   vis[root]=1;
   while(!q.empty()){
     temp = q.front();
     q.pop();
     for(auto it:adj[temp]){
          if(!vis[it]){
            vis[it] = 1;
            q.push(it);
            cout << temp <<" "<< it << endl;
          }
     }
   }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int main() {

    IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}

	// cout<<"\nMAX: "<<max1<<" and temp: "<<temp<<endl;
	unordered_set<int,custom_hash> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}

	while(s2.empty()==false) {
		flag=0;
    	for(auto it=s1.begin();it!=s1.end();it++) {
    		x = *it;
    		for(j=0;j<a[x].size();j++) {
    			if(s2.find(a[x][j])!=s2.end()) {
    				v.pb({x,a[x][j]});
    				s1.insert(a[x][j]);
    				flag=1;
    				break;
    			}
    		}
    		if(flag) {
    			s2.erase(a[x][j]);
    			break;
    		}
    	}
    }
	// cout<<"Printing edges: ";
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}

int main() {

    // IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}

	// cout<<"\nMAX: "<<max1<<" and temp: "<<temp<<endl;
	unordered_set<int> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}
	// cout<<"Printing sets: "<<endl;
	// cout<<"S1: ";
	// for(auto it=s1.begin();it!=s1.end();it++)
	// 	cout<<*it<<" ";

	// cout<<"\nS2: ";
	// for(auto it=s2.begin();it!=s2.end();it++)
	// 	cout<<*it<<" ";

	// cout<<endl;
	while(s2.empty()==false) {
		flag=0;
    	for(auto it=s1.begin();it!=s1.end();it++) {
    		x = *it;
    		for(j=0;j<a[x].size();j++) {
    			if(s2.find(a[x][j])!=s2.end()) {
    				v.pb({x,a[x][j]});
    				s1.insert(a[x][j]);
    				flag=1;
    				break;
    			}
    		}
    		if(flag) {
    			s2.erase(a[x][j]);
    			break;
    		}
    	}
    }
	// cout<<"Printing edges: ";
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}

void bfs(vector<int>a[], vector<pair<int,int>> &v, int x, bool visited[], int n ) {
	queue<int>q;
	q.push(x);
	visited[x]=true;
	while(q.empty()==false) {
		int temp = q.front();
		q.pop();
		for(auto i: a[temp]) {
			if(visited[i]==false) {
				v.pb({i,temp});
				visited[i]=true;
				q.push(i);
			}
			if(v.size()==n-1)
				return ;
		}
	}
}
int main() {

    IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}
	unordered_set<int> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}
	bool visited[n+1];
	for(i=1;i<=n;i++) {
		if(s2.find(i)!=s2.end())
			visited[i]=false;
		else
			visited[i]=true;
	}
	bfs (a, v, temp, visited, n);
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<vector<int>> g;
vector<int> deg, used;
vector<pair<int, int>> ans;

mt19937 rnd(time(NULL));

void bfs(int s) {
	used = vector<int>(n);
	used[s] = 1;
	queue<int> q;
	q.push(s);

	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto to : g[v]) {
			if (used[to]) continue;
			if (rnd() & 1) ans.push_back(make_pair(v, to));
			else ans.push_back(make_pair(to, v));
			used[to] = 1;
			q.push(to);
		}
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	g = vector<vector<int>>(n);
	deg = vector<int>(n);
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
		g[y].push_back(x);
		++deg[x];
		++deg[y];
	}

	int pos = 0;
	for (int i = 0; i < n; ++i) {
		if (deg[pos] < deg[i]) {
			pos = i;
		}
	}

	bfs(pos);
	shuffle(ans.begin(), ans.end(), rnd);
	for (auto it : ans) cout << it.first + 1 << " " << it.second + 1 << endl;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}

void bfs(vector<int>a[], vector<pair<int,int>> &v, int x, bool visited[], int n ) {
	queue<int>q;
	q.push(x);
	visited[x]=true;
	while(q.empty()==false) {
		int temp = q.front();
		q.pop();
		for(auto i: a[temp]) {
			if(visited[i]==false) {
				if(v.size()==n-1)
					return ;

				v.pb({i,temp});
				visited[i]=true;
				q.push(i);
			}
		}
	}
}
int main() {

    IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}
	unordered_set<int> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}
	bool visited[n+1];
	for(i=1;i<=n;i++) {
		if(s2.find(i)!=s2.end())
			visited[i]=false;
		else
			visited[i]=true;
	}
	bfs (a, v, temp, visited, n);
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}

void bfs(vector<int>a[], vector<pair<int,int>> &v, int x, bool visited[], int n ) {
	queue<int>q;
	q.push(x);
	visited[x]=true;
	while(q.empty()==false) {
		int temp = q.front();
		q.pop();
		for(auto i: a[temp]) {
			if(visited[i]==false) {
				v.pb({i,temp});
				visited[i]=true;
				q.push(i);
			}
		}
	}
}
int main() {

    IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}
	unordered_set<int> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}
	bool visited[n+1];
	for(i=1;i<=n;i++) {
		if(s2.find(i)!=s2.end())
			visited[i]=false;
		else
			visited[i]=true;
	}
	bfs (a, v, temp, visited, n);
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
using namespace std;
ll power(ll n,ll m) {if(m==0)return 1;ll t=power(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a,b);}
ll power_with_modulo(ll a, ll b, ll n){ll x=1, y=a; while (b > 0) {if (b%2 == 1) {x = (x*y) % n;}y = (y*y) % n;b /= 2;}return x % n;}
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
string itb(ll n){string s="";while(n>0){ll d = n%2;s = (char)(d+48)+s;n=n/2;}return s;}     // integer to binary
ll bti(string s){ll ans=0,n=s.length();for(int i=0;i<n;i++){ans += (int)(s[n-1-i]-48)*power(2,i);}return ans;}

#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

void print_a(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;}
void print_v(vector<int>v) {for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void print_v1(vector<pair<int,int>>v) {for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int main() {

    // IOS;
    int t,i,j,n,m,x,y,temp,flag;

	int max1 = -10;
	cin>>n>>m;
	vector<int>a[n+1];
	vector<pair<int,int>>v;
	for(i=0;i<m;i++) {
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++) {
		x = a[i].size();
		if(x > max1) {
			max1 = x;
			temp = i;
		}
	}

	// cout<<"\nMAX: "<<max1<<" and temp: "<<temp<<endl;
	unordered_set<int,custom_hash> s1,s2;
	s1.insert(temp);

	for(j=0;j<a[temp].size();j++) {
		v.pb({temp,a[temp][j]});
		s1.insert(a[temp][j]);
	}

	for(i=1;i<=n;i++) {
		if(s1.find(i)==s1.end())
			s2.insert(i);
	}

	while(s2.empty()==false) {
		flag=0;
    	for(auto it=s1.begin();it!=s1.end();it++) {
    		x = *it;
    		for(j=0;j<a[x].size();j++) {
    			if(s2.find(a[x][j])!=s2.end()) {
    				v.pb({x,a[x][j]});
    				s1.insert(a[x][j]);
    				flag=1;
    				break;
    			}
    		}
    		if(flag) {
    			s2.erase(a[x][j]);
    			break;
    		}
    	}
    }
	// cout<<"Printing edges: ";
    for(i=0;i<v.size();i++)
    	cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v,e,x,y,i,max=INT_MIN,z,c=0;
    cin>>v>>e;
    vector<pair<int,int>>g;
    vector<pair<int,int>>a;
    int visited[v+1]={0};
    int indegree[v+1]={0};
    for(i=0;i<e;i++)
    {
    cin>>x>>y;
    g.push_back(make_pair(x,y));
    indegree[x]++;
    indegree[y]++;
    }
    for(i=1;i<=v;i++)
    {
        if(indegree[i]>max)
        {
            max=indegree[i];
            z=i;
        }
    }
    for(i=0;i<g.size();i++)
    {
        if(g[i].first==z || g[i].second==z)
        {
            visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
    for(i=0;i<g.size() && c!=v-1;i++)
    {
        if(visited[g[i].first]==0 || visited[g[i].second]==0 )
        {
             visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
   if(c<v-1)
   {
       for(i=0;i<g.size() && c!=v-1;i++)
       {
           auto p=make_pair(g[i].first,g[i].second);
           if(find(a.begin(),a.end(),p)==a.end())
           {
               a.push_back(make_pair(g[i].first,g[i].second));
            c++;
           }
       }
   }

  for(i=0;i<a.size();i++)
  {
      cout<<a[i].first<<" "<<a[i].second<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v,e,x,y,i,max=INT_MIN,z,c=0;
    cin>>v>>e;
    vector<pair<int,int>>g;
    vector<pair<int,int>>a;
    int visited[v+1]={0};
    int indegree[v+1]={0};
    for(i=0;i<e;i++)
    {
    cin>>x>>y;
    g.push_back(make_pair(x,y));
    indegree[x]++;
    indegree[y]++;
    }
    for(i=1;i<=v;i++)
    {
        if(indegree[i]>max)
        {
            max=indegree[i];
            z=i;
        }
    }
    for(i=0;i<g.size();i++)
    {
        if(g[i].first==z || g[i].second==z)
        {
            visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
    for(i=0;i<g.size() && c<v;i++)
    {
        if(visited[g[i].first]==0 || visited[g[i].second]==0 )
        {
             visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
  for(i=0;i<a.size();i++)
  {
      cout<<a[i].first<<" "<<a[i].second<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int v,e,x,y,i,max=INT_MIN,z,c=0;
    cin>>v>>e;
    vector<pair<long long int,long long int>>g;
    vector<pair<long long int,long long int>>a;
   long long int visited[v+1]={0};
   long long int indegree[v+1]={0};
    for(i=0;i<e;i++)
    {
    cin>>x>>y;
    g.push_back(make_pair(x,y));
    indegree[x]++;
    indegree[y]++;
    }
    for(i=1;i<=v;i++)
    {
        if(indegree[i]>max)
        {
            max=indegree[i];
            z=i;
        }
    }
    for(i=0;i<g.size();i++)
    {
        if(g[i].first==z || g[i].second==z)
        {
            visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
    for(i=0;i<g.size() && c<v-1;i++)
    {
        if(visited[g[i].first]==0 || visited[g[i].second]==0 )
        {
             visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }

  for(i=0;i<a.size();i++)
  {
      cout<<a[i].first<<" "<<a[i].second<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v,e,x,y,i,max=INT_MIN,z,c=0;
    cin>>v>>e;
    vector<pair<int,int>>g;
    vector<pair<int,int>>a;
    int visited[v+1]={0};
    int indegree[v+1]={0};
    for(i=0;i<e;i++)
    {
    cin>>x>>y;
    g.push_back(make_pair(x,y));
    indegree[x]++;
    indegree[y]++;
    }
    for(i=1;i<=v;i++)
    {
        if(indegree[i]>max)
        {
            max=indegree[i];
            z=i;
        }
    }
    for(i=0;i<g.size();i++)
    {
        if(g[i].first==z || g[i].second==z)
        {
            visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }
    for(i=0;i<g.size() && c<v-1;i++)
    {
        if(visited[g[i].first]==0 || visited[g[i].second]==0 )
        {
             visited[g[i].first]=1;
            visited[g[i].second]=1;
            a.push_back(make_pair(g[i].first,g[i].second));
            c++;
        }
    }

  for(i=0;i<a.size();i++)
  {
      cout<<a[i].first<<" "<<a[i].second<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
void linkgraph(vector<int>adj[],int x,int y)
{
    adj[x].push_back(y);
    adj[y].push_back(x);
}
int main()
{
    long long int v,e,x,y,i,max=INT_MIN,z,c=0;
    cin>>v>>e;
    vector<pair<long long int,long long int>>g;
    vector<pair<long long int,long long int>>a;
    vector<int>adj[v+1];
   long long int visited[v+1]={0};
   long long int indegree[v+1]={0};
   queue<int>q;
    for(i=0;i<e;i++)
    {
    cin>>x>>y;
    g.push_back(make_pair(x,y));
    indegree[x]++;
    indegree[y]++;
    linkgraph(adj,x,y);
    }
    for(i=1;i<=v;i++)
    {
        if(indegree[i]>max)
        {
            max=indegree[i];
            z=i;
        }
    }
    q.push(z);
        visited[z]=1;
    while(!q.empty())
    {

        y=q.front();
        q.pop();
        for(auto x:adj[y])
        {
            if(visited[x]==0)
            {
                a.push_back(make_pair(x,y));
                q.push(x);
                visited[x]=1;
            }
        }
    }
  for(i=0;i<a.size();i++)
  {
      cout<<a[i].first<<" "<<a[i].second<<endl;

  }

}


#define boostit ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define print(a) cout<<a<<endl
#define sorted(a) sort(arr.begin(), arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
#define f(i,n) for(ll i=0;i<n;i++)
#define pown  1<<n
#define mid  n>>1
#define mod 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
int main()
{
 boostit;
 ll t;
 t=1;
 //cin>>t;
  while(t--)
   {
     ll n,k,m,b,c;
     cin>>n>>m;
     ll arr[n];
     for(ll i=0;i<n;i++)cin>>arr[i];
     sort(arr,arr+n);
     ll ans=0;
     for(ll i=2;i<n;i+=3){/*cout<<arr[i]<<" ";*/if((5-arr[i])>m)ans++;}
     print(ans);
   }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


#define boostit ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define print(a) cout<<a<<endl
#define sorted(a) sort(arr.begin(), arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
int main()
{
 boostit;
 ll t;
 t=1;
  while(t--)
   {
     ll n,k;
     cin>>n>>k;
     ll arr[n],sum=0;
     for(ll i=0;i<n;i++)cin>>arr[i];
     sort(arr,arr+n);
     for(ll i=2;i<n;i+=3)
      {
        if(5-arr[i] >= k)
           sum++;
      }
     cout<<sum<<endl;
   }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
     int x,y,a[1000],q=0;
     cin >> x >> y;

      for (int i=0;i<x;i++)
      {
          cin >> a[i];
      }

          for (int i=0;i<x;i++)
          {
              a[i] = a[i]+y;
              if (a[i]<=5){q++;}
          }

      cout << q/3;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
     int x,y,a[1000],q=0;
     cin >> x >> y;

      for (int i=0;i<x;i++)
      {
          cin >> a[i];
          a[i] = a[i]+y;
            if (a[i]<=5){q++;}
      }

      cout << q/3;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{

     int x,y,a[1000],q=0;
     scanf ("%d%d",&x,&y);

      for (int i=0;i<x;i++)
      {
          scanf ("%d",&a[i]);
          a[i] = a[i]+y;
            if (a[i]<=5){q++;}
      }

      cout << q/3;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{

     int x,y,z,q=0;
     scanf ("%d%d",&x,&y);

      for (int i=0;i<x;i++)
      {
          scanf ("%d",&z);

            if (z+y<=5){q++;}
      }

      cout << q/3;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{

     int x,y,a[1000],q=0;
     scanf ("%d%d",&x,&y);

      for (int i=0;i<x;i++)
      {
          scanf ("%d",&a[i]);

            if (a[i]+y<=5){q++;}
      }

      cout << q/3;

    return 0;
}