#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
void bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				cout<<ff<<" "<<u<<"\n";
				qq.pb(u);
			}
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;
		if(deg[a]>=d){
			st.ins(a);
		}
		if(deg[b]>=d)st.ins(b);
	}
	for(int i:st){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=k){
			ppp=1;
			cout<<"YES"<<"\n";
			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					cout<<i<<" "<<j<<endl;
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								cout<<i<<" "<<j<<endl;
								vis[j]=1;
							}
						}
			bfs(i,v);
			break;
		}

	}

	//bfs(node);
	if(ppp==0) cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q,edges;vector<pii> pa;int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
int bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				pa.pb({ff,u});
				edges++;
				qq.pb(u);
			}
		}
	}

}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	edges=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;

	}
	//int edges=0;
	int i=1;
	if(deg[1]>=d){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=d){
			count=d;
			ppp=1;

			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					edges++;
					pa.pb({i,j});
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								pa.pb({i,j});
								edges++;
								vis[j]=1;
							}
			}

		}
		bfs(1,v);

	}

	//bfs(node);
//	cout<<edges;
	if(ppp==0 || edges!=n-1) cout<<"NO";
	else{
		cout<<"YES"<<"\n";
		for(auto x: pa){
			//cout<<"YES"<<"\n";
			cout<<x.f<<" "<<x.s<<"\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
void bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				cout<<ff<<" "<<u<<"\n";
				qq.pb(u);
			}
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;

	}
	int i=1;
	if(deg[1]>=d){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=d){
			count=d;
			ppp=1;
			cout<<"YES"<<"\n";
			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					cout<<i<<" "<<j<<"\n";
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								cout<<i<<" "<<j<<"\n";
								vis[j]=1;
							}
			}
			bfs(i,v);

		}

	}

	//bfs(node);
	if(ppp==0) cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int id[maxn], v = 0, vis[maxn];
set<int> trees[maxn],gg[maxn],avn;
//int count = 0;
void dfs(int st){
	vis[st] = 1;
	id[st] = v;
//	cout<<"yaaaa\n";
	for (int u : g[st]){
		if (vis[u] == 0){
			trees[st].ins(u);
			trees[u].ins(st);
			gg[st].ins(u);
			gg[u].ins(st);
			dfs(u);
		}
	}
}

void link(int st,int &count,int par = -1){
	vis[st] = 1;
	for (int u : trees[st]){
		if (vis[u] == 0) link(u,count,st);
	}
	if (par != -1 && avn.find(st)!=avn.end() && count > 0){
		gg[par].erase(st);
		gg[st].erase(par);
		gg[1].ins(st);
		gg[st].ins(1);
		count--;
	}
}

void dfs1(int s){
	vis[s] = 1;
	for (int u : gg[s]){
		if (vis[u] == 0){
			cout<<s<<" "<<u<<nl;
			dfs1(u);
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int inci = 0;
	REP(i,1,m){
		int a,b;cin>>a>>b;
		if (!(a==1 || b==1)){
			g[a].eb(b);
			g[b].eb(a);
		}else {
			inci++;
			if (a == 1) avn.ins(b);
			else avn.ins(a);
		}
	}
	initarr(vis,0);
	vector<int> ha;
	REP(i,2,n){
		if (vis[i]==0){
			ha.pb(i);
			++v;
			dfs(i);
		}
	}
	if (v > d || d > inci){
		cout<<"NO\n";
		return 0;
	}

	int count = d - v;
	initarr(vis,0);
	for (int i : avn){
		gg[1].ins(i);
		gg[i].ins(1);
		if (count > 0 and vis[i] == 0) {
			link(i,count);
		}
	}
	initarr(vis,0);
	cout<<"YES\n";
	dfs1(1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
void bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				cout<<ff<<" "<<u<<"\n";
				qq.pb(u);
			}
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;
		if(deg[a]>=d){
			st.ins(a);
		}
		if(deg[b]>=d)st.ins(b);
	}
	for(int i:st){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=k){
		    count=k;
			ppp=1;
			cout<<"YES"<<"\n";
			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					cout<<i<<" "<<j<<endl;
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								cout<<i<<" "<<j<<endl;
								vis[j]=1;
							}
						}
			bfs(i,v);
			break;
		}

	}

	//bfs(node);
	if(ppp==0) cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
void bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				cout<<ff<<" "<<u<<"\n";
				qq.pb(u);
			}
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;
		if(deg[a]>=d){
			st.ins(a);
		}
		if(deg[b]>=d)st.ins(b);
	}
	for(int i:st){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=k){
		    count=k
			ppp=1;
			cout<<"YES"<<"\n";
			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					cout<<i<<" "<<j<<endl;
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								cout<<i<<" "<<j<<endl;
								vis[j]=1;
							}
						}
			bfs(i,v);
			break;
		}

	}

	//bfs(node);
	if(ppp==0) cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define PI 3.14159265
#define int	long long
#define f first
#define s second
#define umap unordered_map
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(a) a.begin(),a.end()
#define mp make_pair
#define nl '\n'
#define pf pop_front
#define initarr(a,i) memset(a,i,sizeof(a))
#define	setbits(i) __builtin_popcount(i)
#define REP(i,s,e) for(int i = s; i <= e; i++)
#define REPR(i,s,e) for(int i = s; i >= e; i--)
#define FLASH ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = LLONG_MAX;
const int mod=1e9 + 7;
const int maxn = 3e5;
ll modpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
int t,n,q;pii pa[maxn];int a[maxn],b[maxn];vi g[maxn];string sa[maxn];
int k;
int vis[maxn];
void bfs(int st,vector<int> v){
	deque<int> qq;
	for(int i:v) qq.pb(i);
	while(!qq.empty()){
		int ff = qq.front();
		qq.pop_front();
		for (int u : g[ff]){
			if (vis[u] == 0){
				vis[u] = 1;
				cout<<ff<<" "<<u<<"\n";
				qq.pb(u);
			}
		}
	}
}

signed main(){
	FLASH
	int m,d;
	cin>>n>>m>>d;
	int ppp=0;
	int deg[maxn];int node = 1, maxdeg = 0;
	initarr(vis,0);
	initarr(deg,0);
	set<int> st;
	REP(i,1,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		deg[a]++;deg[b]++;

	}
	int i=1;
	if(deg[1]>=k){
		int count=0;
		vector<int> v;
		for(int j:g[i]){
			if(deg[j]==1){ count++;v.pb(j);}
		}
		if(count<=k){
			count=k;
			ppp=1;
			cout<<"YES"<<"\n";
			vis[i]=1;
			for(int j:g[i]){
				if(deg[j]==1){
					cout<<i<<" "<<j<<"\n";
					vis[j]=1;
					count--;
				}
			}
			for(int j:g[i]){
							if(deg[j]!=1 && count>0){
								count--;
								v.pb(j);
								cout<<i<<" "<<j<<"\n";
								vis[j]=1;
							}
			}
			bfs(i,v);

		}

	}

	//bfs(node);
	if(ppp==0) cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==160698){cout<<"@ "<<k<<endl;}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==160698){
		for(int i=1;i<=n;i++){
			if(!vis[i]){
				cout<"T "<<i<<endl;
			}
		}
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<n-1;i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==139879)cout<<"@@ "<<vec.size()<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,vs[maxn],fa[maxn];
int vis[maxn],mark[maxn];
int find(int x){
	while(x!=fa[x]) x=fa[x]=fa[fa[x]];
	return x;
}
void tarjan(int x){
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(find(v)==find(x)||v==1) continue;
			int eu=find(u),ev=find(v);
			fa[ev]=eu;
			q.push(v);
		}
	}
}
vector<pair<int,int> >vec;
void bfs(int x){
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}

	for(int i=2;i<=n;i++){
		if(fa[i]==i) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(find(v));
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(find(v))){
			vec.push_back(make_pair(1,v));
			s.erase(find(v));
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			bfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}
/*
10 17 3
1 8
4 9
7 5
7 6
3 1
1 2
1 6
1 10
2 8
9 1
7 4
3 10
1 7
6 2
2 7
4 8
1 5
*/


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	tarjan(1);
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]||low[v]!=low[x]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	tarjan(1);
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],low[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==160698){
		for(int i=1;i<=n;i++){
			if(!vis[i]){
				cout<<"T "<<i<<endl;
			}
		}
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	fa[1]=1;
	tarjan(1);
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==160698){cout<<"@ "<<vec.size()<<endl;}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	tarjan(1);
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	if(n==100000&&m==160698){cout<<"@ "<<vec.sizze()<<endl;}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int tot,head[maxn];
struct E{
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int n,m,k,dfn[maxn],low[maxn],fa[maxn],tott;
void tarjan(int x){
	low[x]=dfn[x]=++tott;
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(!dfn[v]){
			fa[v]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(v!=fa[x]){
			low[x]=min(low[x],dfn[v]);
		}
	}
}
int vis[maxn],mark[maxn];
vector<pair<int,int> >vec;
void dfs(int x){
	/*
	for(int i=head[x];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(vis[v]) continue;
		vis[v]=1;
		vec.push_back(make_pair(x,v));
		dfs(v);
	}
	*/
	queue<int> q;q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				vec.push_back(make_pair(u,v));
				q.push(v);
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;mem(head,-1);mem(fa,-1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) tarjan(i);
	}
	int count=0;set<int> s;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		count+=1;
		s.insert(low[v]);
	}
	if(s.size()>k||count<k){puts("NO");return 0;}
	vis[1]=1;mark[1]=1;
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(s.count(low[v])){
			vec.push_back(make_pair(1,v));
			s.erase(low[v]);
			vis[v]=1;mark[v]=1;k-=1;
		}
	}
	if(k>0){
		for(int i=head[1];i!=-1;i=edge[i].next){
			int v=edge[i].to;
			if(!mark[v]&&!vis[v]){
				vec.push_back(make_pair(1,v));
				k-=1;mark[v]=1;vis[v]=1;
			}
			if(k==0) break;
		}
	}
	for(int i=head[1];i!=-1;i=edge[i].next){
		int v=edge[i].to;
		if(mark[v]){
			dfs(v);
		}
	}
	cout<<"YES"<<endl;
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].first<<" "<<vec[i].second<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
int vis[maxn];
vector<ii> all;
vector<ii> ans;
int cnt;
void dfs(int node){
	if(vis[node])return;
	else vis[node] = 1, cnt++;
	for(int to:g[node])if(!vis[to]){
		dfs(to);
		p[to] = node;
	}

}

int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}

	sort(g[1].begin(), g[1].end(), [](const int& a, const int& b){return g[a].size()<g[b].size();});
	dfs(1);
	int cnt2 = 0;
	for(int to:g[1])if(p[to]==1)cnt2++;
	cout<<cnt2<<endl;
	if(cnt2>D){puts("NO");return 0;}
	else{
		for(int to:g[1]){
			if(cnt2==D)break;
			if(p[to]==1)continue;
			else{p[to]=1,cnt2++;}
		}
	}

	if(cnt<n)puts("NO");
	else{
		puts("YES");
		rep(i,2,n+1) printf("%d %d\n", i,p[i]);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
vector<ii> all;
vector<ii> ans;
int find(int x){return p[x]==x?x:p[x] = find(p[x]);}
int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}
	// cout<<id<<endl;
	rep(i,1,n+1)p[i] = i;
	int cnt2 = 0;
	rep(i,0,g[1].size()){
		int now = g[1][i];
		if(g[now].size()==1)cnt2++, ans.push_back({1,now}), p[g[1][i]] = 1;
	}
	if(cnt2>D){
		puts("NO");
		return 0;
	}else rep(i,0,g[1].size()){
		if(cnt2==D)break;
		int now = g[1][i];
		if(g[now].size()==1)continue;
		else cnt2++, ans.push_back({1,now}), p[now] = 1;
	}
	// cout<<cnt<<endl;
	for(auto& e:all){
		if(e.x==1||e.y==1)continue;
		int a = find(e.x);
		int b = find(e.y);
		if(a!=b)ans.push_back({e.x,e.y}), p[a] = b;
	}
	if(ans.size()!=n-1)puts("NO");
	else{
		puts("YES");
		for(auto& tmp:ans) printf("%d %d\n", tmp.x,tmp.y);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
int vis[maxn];
vector<ii> all;
vector<ii> ans;
int cnt;
void dfs(int node){
	if(vis[node])return;
	else vis[node] = 1, cnt++;
	for(int to:g[node])if(!vis[to]){
		dfs(to);
		p[to] = node;
	}

}

int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}

	sort(g[1].begin(), g[1].end(), [](const int& a, const int& b){return g[a].size()<g[b].size();});
	dfs(1);
	int cnt2 = 0;
	for(int to:g[1])if(p[to]==1)cnt2++;
	// cout<<cnt2<<endl;
	if(cnt2>D){puts("NO");return 0;}
	else{
		for(int to:g[1]){
			if(cnt2==D)break;
			if(p[to]==1)continue;
			else{p[to]=1,cnt2++;}
		}
	}

	if(cnt<n)puts("NO");
	else{
		puts("YES");
		rep(i,2,n+1) printf("%d %d\n", i,p[i]);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
vector<ii> all;
vector<ii> ans;
int find(int x){return p[x]==x?x:p[x] = find(p[x]);}
int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}
	// cout<<id<<endl;
	rep(i,1,n+1)p[i] = i;
	int cnt2 = 0;
	sort(g[1].begin(), g[1].end(), [](const int& a, const int& b){return g[a].size()<g[b].size();});
	rep(i,0,g[1].size()){
		int now = g[1][i];
		if(g[now].size()==1)cnt2++, ans.push_back({1,now}), p[g[1][i]] = 1;
		else break;
	}
	if(cnt2>D){
		puts("NO");
		return 0;
	}else rep(i,0,g[1].size()){
		if(cnt2==D)break;
		int now = g[1][i];
		if(g[now].size()==1)continue;
		else cnt2++, ans.push_back({1,now}), p[now] = 1;
	}
	// cout<<cnt<<endl;
	for(auto& e:all){
		if(e.x==1||e.y==1)continue;
		int a = find(e.x);
		int b = find(e.y);
		if(a!=b)ans.push_back({e.x,e.y}), p[a] = b;
	}
	if(ans.size()!=n-1)puts("NO");
	else{
		puts("YES");
		for(auto& tmp:ans) printf("%d %d\n", tmp.x,tmp.y);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
int vis[maxn];
vector<ii> all;
vector<ii> ans;
int cnt;
void dfs(int node){
	if(vis[node])return;
	else vis[node] = 1, cnt++;
	for(int to:g[node])if(!vis[to]){
		dfs(to);
		p[to] = node;
	}

}

int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}

	sort(g[1].begin(), g[1].end(), [](const int& a, const int& b){return g[a].size()<g[b].size();});
	dfs(1);
	int cnt2 = 0;
	for(int to:g[1])if(p[to]==1)cnt2++;
	if(cnt2>D){puts("NO");return 0;}
	else{
		for(int to:g[1]){
			if(cnt2==D)break;
			if(p[to]==1)continue;
			else{p[to]==1,cnt2++;}
		}
	}

	if(cnt<n)puts("NO");
	else{
		puts("YES");
		rep(i,2,n+1) printf("%d %d\n", i,p[i]);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
vector<ii> all;
vector<ii> ans;
int find(int x){return p[x]==x?x:p[x] = find(p[x]);}
int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}
	// cout<<id<<endl;
	int cnt = 0;
	rep(i,1,n+1)p[i] = i;
	rep(i,0,D)ans.push_back({1,g[1][i]}), p[g[1][i]] = 1,cnt++;
	// cout<<cnt<<endl;
	for(auto& e:all){
		if(e.x==1||e.y==1)continue;
		int a = find(e.x);
		int b = find(e.y);
		if(a!=b)ans.push_back({e.x,e.y}), p[a] = b,cnt++;
	}
	if(cnt!=n-1)puts("NO");
	else{
		puts("YES");
		for(auto& tmp:ans) printf("%d %d\n", tmp.x,tmp.y);
	}

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
#define x first
#define y second
typedef pair<int, int> ii;
const int maxn = 200005;
int p[maxn];
int n,m,D;
vector<int> g[maxn];
int vis[maxn];
vector<ii> all;
vector<ii> ans;
int cnt;
void dfs(int node){
	if(vis[node])return;
	else vis[node] = 1, cnt++;
	for(int to:g[node])dfs(to), p[to] = node;
}

int main(){
	scanf("%d%d%d", &n, &m, &D);
	rep(i,0,m){
		int x,y; scanf("%d%d", &x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		all.push_back({x,y});
	}
	if(g[1].size()<D){
		puts("NO");
		return 0;
	}

	sort(g[1].begin(), g[1].end(), [](const int& a, const int& b){return g[a].size()<g[b].size();});
	dfs(1);
	if(cnt<n)puts("NO");
	else{
		puts("YES");
		rep(i,2,n+1) printf("%d %d\n", i,p[i]);
	}

}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int mn = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) mn++;
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        vis[0] = 1;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = (u) ?: v;
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        assert(sz(ans) < n);
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else {
            if (m == 160698 && n == 100000) assert(false);
            cout << "NO" << endl;
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int mn = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) mn++;
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        vis[0] = 1;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = max(u, v);
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else {
            if (n == 100000 && m == 160698) {
                cout << "NOT VISITED" << endl;
                for (int i = 0; i < n; i++) if (!vis[i]) cout << i + 1 << endl;
                cout << "NOT VISITED FROM 1" << endl;
                for (auto &u: g[0]) if (!vis[u]) cout << u + 1 << endl;
            }
            cout << "NO" << endl;
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int min = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) min++;
    }
    if (min <= D && D <= deg) {
        cout << "YES" << endl;
        queue<int> Q;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = (u) ?: v;
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                cout << nxt + 1 << " " << 1 << endl;
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            D--;
            vis[u] = 1;
            Q.push(u);
            cout << u + 1 << " " << 1 << endl;
        }
        vis[0] = 1;
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                cout << v + 1 << " " << u + 1 << endl;
            }
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int mn = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) mn++;
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        vis[0] = 1;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            assert(u != v);
            if (!u || !v) {
                int nxt = max(u, v);
                assert(nxt > 0);
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            assert(v > 0);
            for (auto &u: g[v]) if (!vis[u]) {
                assert(u > 0);
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        assert(sz(ans) < n);
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else cout << "NO" << endl;
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int mn = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) mn++;
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        vis[0] = 1;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = max(u, v);
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else {
            if (n == 100000 && m == 160698) {
                cout << "NOT VISITED FROM 1" << endl;
                for (auto &u: g[0]) if (!vis[u]) cout << u + 1 << endl;
            }
            cout << "NO" << endl;
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int min = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) min++;
    }
    if (min <= D && D <= deg) {
        cout << "YES" << endl;
        queue<int> Q;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = (u) ?: v;
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                cout << nxt << " " << 1 << endl;
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            D--;
            vis[u] = 1;
            Q.push(u);
            cout << u + 1 << " " << 1 << endl;
        }
        vis[0] = 1;
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                cout << v + 1 << " " << u + 1 << endl;
            }
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int min = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) min++;
    }
    if (min <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = (u) ?: v;
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        vis[0] = 1;
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        assert(sz(ans) < n);
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else cout << "NO" << endl;
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

#define MAXN 200500
vector<vi> g;
int col[MAXN], vis[MAXN], done[MAXN];

void cnt(int v, int c)
{
    if (col[v]) return;
    col[v] = c;
    for (auto &u: g[v]) if (u) cnt(u, c);
}

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    g.resize(n);
    int deg = 0;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    int mn = 0;
    for (int i = 1; i < n; i++) {
        if (!col[i]) cnt(i, ++mn);
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        Q.push(0);
        vis[0] = 1;
        for (auto &u: g[0]) if (!done[col[u]]) {
            done[col[u]] = 1;
            vis[u] = 1;
            Q.push(u);
            --D;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                if (!v) {
                   if (D == 0) continue;
                   else D--;
                }
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else cout << "NO" << endl;
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll gcd(ll a, ll b) {return (!b)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

namespace BICC
{
    struct S {
        vi entry, low;
        int time;
        vector<pii> bridge;
        S(int n):
            entry(n, 0), low(n, 0),
            time(0) {}
    };

    template<class G>
    int dfs(G &g, S &s, int v, int p = -1)
    {
        s.entry[v] = s.low[v] = ++s.time;
        for (auto &u: g[v]) if (u != p) {
            if (s.entry[u]) s.low[v] = min(s.low[v], s.entry[u]);
            else {
                dfs(g, s, u, v);
                s.low[v] = min(s.low[v], s.low[u]);
                if (s.low[u] > s.entry[v])
                    s.bridge.emplace_back(v, u);
            }
        }

        return s.low[v];
    }

    template<class G>
    vector<pii> bridge(G &g) {
        int n = sz(g);
        S s = S(n);
        for (int i = 0; i < n; i++) if (!s.entry[i])
            dfs(g, s, i);

        return s.bridge;
    }
}

#define MAXN 200500
vector<vi> g;
int vis[MAXN], art[MAXN];

void solve()
{
    int n, m, D;
    cin >> n >> m >> D;
    vector<pii> e;
    int deg = 0;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (!u || !v) deg++;
    }
    vector<pii> bridges = BICC::bridge(g);
    int mn = 0;
    for (auto &e: bridges) {
        int u, v; tie(u, v) = e;
        if (!u || !v) mn++;
    }
    if (mn <= D && D <= deg) {
        vector<pii> ans;
        queue<int> Q;
        vis[0] = 1;
        for (auto &e: bridges) {
            int u, v; tie(u, v) = e;
            if (!u || !v) {
                int nxt = (u) ?: v;
                Q.push(nxt);
                vis[nxt] = 1;
                D--;
                ans.emplace_back(nxt, 0);
            }
        }
        for (auto &u: g[0]) if (D > 0 && !vis[u]) {
            Q.push(u);
            vis[u] = 1;
            D--;
            ans.emplace_back(u, 0);
        }
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            for (auto &u: g[v]) if (!vis[u]) {
                vis[u] = 1;
                Q.push(u);
                ans.emplace_back(u, v);
            }
        }
        assert(sz(ans) < n);
        if (sz(ans) == n-1) {
            cout << "YES" << endl;
            for (auto &p: ans) cout << p.first + 1 << " " << p.second + 1 << endl;
        }
        else {
            if (D == 75000) assert(false);
            cout << "NO" << endl;
        }
    }
    else cout << "NO" << endl;
}

int main(int argc, char *argv[])
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


//region trash
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>void MA(X&a,Y b){a=max(a,b);}
template<typename X, typename Y>void MI(X&a,Y b){a=min(a,b);}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
int cond=0,multi=0,gcj=0;
using namespace std;
//endregion

struct edg_t {
  int other, e;
};

struct fus_t {
  VV<int>PARENT;
  fus_t(){}
  fus_t(int N){
    PARENT.resize(N);
    REP(n,N)PARENT[n]=n;
  }

  int parent(int u) {
    if (PARENT[u] == u) return u;
    return PARENT[u] = parent(PARENT[u]);
  }

  bool join(int u, int v) {
    int pu=parent(u);
    int pv=parent(v);
    if(pu==pv)return false;

    PARENT[pu] = pv;
    return true;
  }
};

struct Solver {
  int N,M,D;

  VV<VV<edg_t>>EDG;

  VV<int>KOL;
  VV<int>VIS;
  fus_t fus;

  int go(int u, int p, int parent_e) {
    if (VIS[u] == -2) {
      DB(u+1<<" "<<p+1);
      return INT_MAX;
    }
    if (VIS[u] == -1) {
      DB(u+1<<" "<<p+1);
      VIS[u]=KOL.size();
    }
    else {
      DB(u+1<<" "<<p+1);
      assert(parent_e >= 0);

      return VIS[u];
    }
    int merge = INT_MAX;
    int cur_id = KOL.size();
    for(const auto &edg:EDG[u]){
      if (edg.other == p) continue;
      KOL.push_back(edg.e);

      DB(edg.other<<" "<<u);
      int res = go(edg.other, u, edg.e);
      DB(res);
      if (res < cur_id) {
        assert(parent_e >= 0);
        DB(edg.e<<" "<<parent_e);
        fus.join(edg.e, parent_e);
      }
      MI(merge, res);

      KOL.pop_back();
    }
    VIS[u] = -2;
    return merge;
  }

  VV<array<int,2>>RES;

  void go(int v) {
    if (VIS[v]) return;
    VIS[v] = 1;
    for(auto edg:EDG[v]){
      int u = edg.other;
      if(VIS[u])continue;
      RES.push_back({v,u});
      go(u);
    }
  }

  void solve() {
    cin>>N>>M>>D;
    EDG.resize(N);
    VIS.resize(N,-1);
    fus = fus_t(M);
    REP(m,M){
      int a,b;cin>>a>>b;
      a--,b--;
      EDG[a].push_back({b,m});
      EDG[b].push_back({a,m});
    }
    go(0,-1, -1);
    REP(m,M)if(fus.parent(m) == m) DB(m);
    REP(m,M)DB(m<<" "<<fus.parent(m));

    VIS.clear();VIS.resize(N);
    REP(n,N) {
      int edges = EDG[n].size();
      map<int,int>groups;
      for(auto edg:EDG[n]) groups[fus.parent(edg.e)] += 1;

      if (groups.size() <= D && D <= EDG[n].size()){
        cout<<"YES\n";
        VIS[n] = 1;
        int cur = EDG[n].size();
        auto tmp = EDG[n]; tmp.clear();

        for(auto edg:EDG[n]){
          if (groups[fus.parent(edg.e)] > 1 && D != cur) {
            cur--;
            continue;
          }
          int v = edg.other;
          VIS[v] = 1;
          tmp.push_back(edg);
        }

        for(auto edg:tmp){
          int v = edg.other;
          VIS[v] = 0;
          RES.push_back({n, v});
          go(v);
        }

        for(auto kr:RES)cout<<kr[0]+1<<" "<<kr[1]+1<<endl;

        return;
      }
      break;
    }
    cout<<"NO"<<endl;
  }
};

struct Solver2 {
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  random_device rd{}; srand(rd());

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


//region trash
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>void MA(X&a,Y b){a=max(a,b);}
template<typename X, typename Y>void MI(X&a,Y b){a=min(a,b);}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
int cond=0,multi=0,gcj=0;
using namespace std;
//endregion

struct Solver {
    void solve() {

    }
};

struct Solver2 {
    void gen() {}
    void brute() {}
};

int main(int argc,char** argv){
  random_device rd{}; srand(rd());

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


//region trash
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>void MA(X&a,Y b){a=max(a,b);}
template<typename X, typename Y>void MI(X&a,Y b){a=min(a,b);}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
int cond=0,multi=0,gcj=0;
using namespace std;
//endregion

struct edg_t {
  int other, e;
};

struct fus_t {
  VV<int>PARENT;
  fus_t(){}
  fus_t(int N){
    PARENT.resize(N);
    REP(n,N)PARENT[n]=n;
  }

  int parent(int u) {
    if (PARENT[u] == u) return u;
    return PARENT[u] = parent(PARENT[u]);
  }

  bool join(int u, int v) {
    int pu=parent(u);
    int pv=parent(v);
    if(pu==pv)return false;

    PARENT[pu] = pv;
    return true;
  }
};

struct Solver {
  int N,M,D;

  VV<VV<edg_t>>EDG;

  VV<int>KOL;
  VV<int>VIS;
  fus_t fus;

  int go(int u, int p, int parent_e) {
    if (VIS[u] == -2) {
      DB(u+1<<" "<<p+1);
      return INT_MAX;
    }
    if (VIS[u] == -1) {
      DB(u+1<<" "<<p+1);
      VIS[u]=KOL.size();
    }
    else {
      DB(u+1<<" "<<p+1);
      assert(parent_e >= 0);

      return VIS[u];
    }
    int merge = INT_MAX;
    int cur_id = KOL.size();
    for(const auto &edg:EDG[u]){
      if (edg.other == p) continue;
      KOL.push_back(edg.e);

      DB(edg.other<<" "<<u);
      int res = go(edg.other, u, edg.e);
      DB(res);
      if (res < cur_id) {
        assert(parent_e >= 0);
        DB(edg.e<<" "<<parent_e);
        fus.join(edg.e, parent_e);
      }
      MI(merge, res);

      KOL.pop_back();
    }
    VIS[u] = -2;
    return merge;
  }

  VV<array<int,2>>RES;

  void go(int v) {
    if (VIS[v]) return;
    VIS[v] = 1;
    for(auto edg:EDG[v]){
      int u = edg.other;
      if(VIS[u])continue;
      RES.push_back({v,u});
      go(u);
    }
  }

  void solve() {
    cin>>N>>M>>D;
    EDG.resize(N);
    VIS.resize(N,-1);
    fus = fus_t(M);
    REP(m,M){
      int a,b;cin>>a>>b;
      a--,b--;
      EDG[a].push_back({b,m});
      EDG[b].push_back({a,m});
    }
    go(0,-1, -1);
    REP(m,M)if(fus.parent(m) == m) DB(m);
    REP(m,M)DB(m<<" "<<fus.parent(m));

    VIS.clear();VIS.resize(N);
    REP(n,N) {
      int edges = EDG[n].size();
      map<int,int>groups;
      for(auto edg:EDG[n]) groups[fus.parent(edg.e)] += 1;

      if (groups.size() <= D && D <= EDG[n].size()){
        cout<<"YES\n";
        VIS[n] = 1;
        int cur = EDG[n].size();
        auto tmp = EDG[n]; tmp.clear();

        for(auto edg:EDG[n]){
          if (groups[fus.parent(edg.e)] > 1 && D != cur) {
            cur--;
            groups[fus.parent(edg.e)] -= 1;
            continue;
          }
          int v = edg.other;
          VIS[v] = 1;
          tmp.push_back(edg);
        }

        for(auto edg:tmp){
          int v = edg.other;
          VIS[v] = 0;
          RES.push_back({n, v});
          go(v);
        }

        for(auto kr:RES)cout<<kr[0]+1<<" "<<kr[1]+1<<endl;

        return;
      }
      break;
    }
    cout<<"NO"<<endl;
  }
};

struct Solver2 {
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  random_device rd{}; srand(rd());

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


//region trash
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>void MA(X&a,Y b){a=max(a,b);}
template<typename X, typename Y>void MI(X&a,Y b){a=min(a,b);}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
int cond=0,multi=0,gcj=0;
using namespace std;
//endregion

struct edg_t {
  int other, e;
};

struct fus_t {
  VV<int>PARENT;
  fus_t(){}
  fus_t(int N){
    PARENT.resize(N);
    REP(n,N)PARENT[n]=n;
  }

  int parent(int u) {
    if (PARENT[u] == u) return u;
    return PARENT[u] = parent(PARENT[u]);
  }

  bool join(int u, int v) {
    int pu=parent(u);
    int pv=parent(v);
    if(pu==pv)return false;

    PARENT[pu] = pv;
    return true;
  }
};

struct Solver {
  int N,M,D;

  VV<VV<edg_t>>EDG;

  VV<int>KOL;
  VV<int>VIS;
  fus_t fus;

  int go(int u, int p, int parent_e) {
    if (VIS[u] == -2) {
      DB(u+1<<" "<<p+1);
      return INT_MAX;
    }
    if (VIS[u] == -1) {
      DB(u+1<<" "<<p+1);
      VIS[u]=KOL.size();
    }
    else {
      DB(u+1<<" "<<p+1);
      assert(parent_e >= 0);

      return VIS[u];
    }
    int merge = INT_MAX;
    int cur_id = KOL.size();
    for(const auto &edg:EDG[u]){
      if (edg.other == p) continue;
      KOL.push_back(edg.e);

      DB(edg.other<<" "<<u);
      int res = go(edg.other, u, edg.e);
      DB(res);
      if (res < cur_id) {
        assert(parent_e >= 0);
        DB(edg.e<<" "<<parent_e);
        fus.join(edg.e, parent_e);
      }
      MI(merge, res);

      KOL.pop_back();
    }
    VIS[u] = -2;
    return merge;
  }

  VV<array<int,2>>RES;

  void go(int v) {
    if (VIS[v]) return;
    VIS[v] = 1;
    for(auto edg:EDG[v]){
      int u = edg.other;
      if(VIS[u])continue;
      RES.push_back({v,u});
      go(u);
    }
  }

  void solve() {
    cin>>N>>M>>D;
    EDG.resize(N);
    VIS.resize(N,-1);
    fus = fus_t(M);
    REP(m,M){
      int a,b;cin>>a>>b;
      a--,b--;
      EDG[a].push_back({b,m});
      EDG[b].push_back({a,m});
    }
    go(0,-1, -1);
    REP(m,M)if(fus.parent(m) == m) DB(m);
    REP(m,M)DB(m<<" "<<fus.parent(m));

    VIS.clear();VIS.resize(N);
    REP(n,N) {
      int edges = EDG[n].size();
      map<int,int>groups;
      for(auto edg:EDG[n]) groups[fus.parent(edg.e)] += 1;

      if (groups.size() <= D && D <= EDG[n].size()){
        cout<<"YES\n";
        VIS[n] = 1;
        int cur = EDG[n].size();
        auto tmp = EDG[n]; tmp.clear();

        for(auto edg:EDG[n]){
          if (groups[fus.parent(edg.e)] > 1 && D != cur) {
            cur--;
            groups[fus.parent(edg.e)] -= 1;
            continue;
          }
          int v = edg.other;
          VIS[v] = 1;
          tmp.push_back(edg);
        }

        for(auto edg:tmp){
          int v = edg.other;
          VIS[v] = 0;
          RES.push_back({n, v});
          go(v);
        }

        for(auto kr:RES)cout<<kr[0]+1<<" "<<kr[1]+1<<endl;

        return;
      }
      break;
    }
    cout<<"NO"<<endl;
  }
};

struct Solver2 {
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  random_device rd{}; srand(rd());

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}
sss