#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=102;
int s[3];
int ans[maxn];
int main()
{
    int i,j,k;
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
       // memset(ans,-1,sizeof(ans));
       for(i=0;i<n;i++)
        ans[i]=-1;
        int l=0;
        for(i=0;i<m;i++)
        {
             k=1;
            for(j=0;j<3;j++)
            {
             // scanf("%d",&s[j]);
               cin>>s[i];
              if(ans[s[j]]!=-1)
              {
                  l=ans[s[j]];
              }
            }
           for(j=0;j<3;j++)
           {
               if(ans[s[j]]!=l)
               {
                   ans[s[j]]=(l+k)%3;
                   k++;
               }
           }
        }
        for(i=0;i<n;i++)
            printf("%d ",ans[i]);
            printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    long int n, m, i;
    cin >> n >> m;
    int dan[n+1], tan[3], col=0, j, k;
    for(i=0; i<n+1; i++)
        dan[i]=-1;
    for(i=0; i<m; i++)
    {
        k=1;
        for(j=0; j<3; j++)
        {
            cin >> tan[j];
            if(dan[tan[j]]!=-1)
            {
                col=dan[tan[j]];
                cout<<col<<"**";
            }
        }
        for(j=0; j<3; j++)
            if(dan[tan[j]]!=col)
            {
                dan[tan[j]]=(col+k)%3;
                k++;
                cout<<dan[tan[j]]<<"@@";
            }
    }
    for(i=1; i<n+1; i++)
        cout << dan[i]+1 << " ";
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1000002;
int s[3];
int ans[maxn];
int main()
{
    int i,j,k;
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(ans,-1,sizeof(ans));
      // int ans[n+1];
       //for(i=1;i<=n;i++)
       // ans[i]=-1;
        int l=0;
        for(i=0;i<m;i++)
        {
             k=1;
            for(j=0;j<3;j++)
            {
             // scanf("%d",&s[j]);
               cin>>s[j];
              if(ans[s[j]]!=-1)
              {
                  l=ans[s[j]];
              }
            }
           for(j=0;j<3;j++)
               if(ans[s[j]]!=l)
               {
                   ans[s[j]]=(l+k)%3;
                   k++;
               }
        }
        for(i=1;i<=n;i++)
            printf("%d ",ans[i]+1);
            printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    long int n, m, i;
    cin >> n >> m;
    int dan[n+1], tan[3], col=0, j, k;
    for(i=0; i<n+1; i++)
        dan[i]=-1;
    for(i=0; i<m; i++)
    {
        k=1;
        for(j=0; j<3; j++)
        {
            cin >> tan[j];
            if(dan[tan[j]]!=-1)
            {
                col=dan[tan[j]];
              //  cout<<col<<"**";
            }
        }
        for(j=0; j<3; j++)
            if(dan[tan[j]]!=col)
            {
                dan[tan[j]]=(col+k)%3;
                k++;
               // cout<<dan[tan[j]]<<"@@";
            }
    }
    for(i=1; i<n+1; i++)
        cout << dan[i]+1 << " ";
        return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    a++;
    int dif[a][a];
    for(int i(0);i<b;i++)
    {
        int k[3];
        cin>>k[0]>>k[1]>>k[2];
        for(int j(0);j<3;j++)
        {
            for(int p(0);p<3;p++)
                {
                    if(j==p){continue;}
                    dif[k[j]][k[p]]=1;
                }
        }
    }
    int colour[a];
    for(int i(1);i<a;i++)
    {
     colour[i]=0;
    }
    for(int i(1);i<a;i++)
    {
        int q;
        do
        {
            colour[i]++;
            if(colour[i]>3){colour[i]=1;}
            q=0;
            for(int j(1);j<a;j++)
            {
                if(dif[i][j]==1&&colour[i]==colour[j]){q=1;break;}
            }
        }while(q==1);
    }
    for(int i(1);i<a;i++)
    {
     cout<<colour[i]<<" ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    a++;
    int dif[a][a];
    for(int i(0);i<a;i++)
    {
        for(int j(0);j<a;j++)
        {
            dif[i][j]=0;
        }
    }
    for(int i(0);i<b;i++)
    {
        int k[3];
        cin>>k[0]>>k[1]>>k[2];
        for(int j(0);j<3;j++)
        {
            for(int p(0);p<3;p++)
                {
                    if(j==p){continue;}
                    dif[k[j]][k[p]]=1;
                }
        }
    }
    int colour[a];
    for(int i(1);i<a;i++)
    {
     colour[i]=0;
    }
    for(int i(1);i<a;i++)
    {
        int q;
        do
        {
            colour[i]++;
            q=0;
            for(int j(1);j<a;j++)
            {
                if(dif[i][j]==1&&colour[i]==colour[j]){q=1;break;}
            }
        }while(q==1);
    }
    for(int i(1);i<a;i++)
    {
     cout<<colour[i]<<" ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    a++;
    int dif[a][a];
    for(int i(0);i<b;i++)
    {
        int k[3];
        cin>>k[0]>>k[1]>>k[2];
        for(int j(0);j<3;j++)
        {
            for(int p(0);p<3;p++)
                {
                    if(j==p){continue;}
                    dif[k[j]][k[p]]=1;
                }
        }
    }
    int colour[a];
    for(int i(1);i<a;i++)
    {
     colour[i]=0;
    }
    for(int i(1);i<a;i++)
    {
        int q;
        do
        {
            colour[i]++;
            q=0;
            for(int j(1);j<a;j++)
            {
                if(dif[i][j]==1&&colour[i]==colour[j]){q=1;break;}
            }
        }while(q==1);
    }
    for(int i(1);i<a;i++)
    {
     cout<<colour[i]<<" ";
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define RREP(i,n) RFOR(i, n-1, 0)
#define ECH(it, v) for(typeof(v.begin()) it=v.begin();it!=v.end();++it)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define sz size()
#define mkp make_pair
int _neg=0;
#define NEG return --_neg;
#define MOD 1000000007
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

void solve() {
	int n, m;;
	cin>>n>>m;
	int a[m][3];
	int c[n];
	REP(i, n) c[i] = 0;
	REP(i, m) {
		int aa, bb, cc;
		cin>>aa>>bb>>cc;
		aa--; bb--; cc--;
		int ia, ib, ic;
		if(c[aa]) ia = aa, ib = bb, ic = cc;
		else if(c[bb]) ia = bb, ib = aa, ic = cc;
		else if(c[cc]) ia = cc, ib = bb, ic = aa;
		else ia = 0;
		if(!ia) c[aa] = 1, c[bb] = 2, c[cc] = 3;
		else if(c[ia] == 1) c[ib] = 2, c[ic] = 3;
		else if(c[ia] == 2) c[ib] = 1, c[ic] = 3;
		else if(c[ia] == 3) c[ib] = 2, c[ic] = 1;
	}
	REP(i, n) cout<<c[i]<<" ";

}

int main() {
    x:
    solve();
	cout<<endl;

    /**/
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define RREP(i,n) RFOR(i, n-1, 0)
#define ECH(it, v) for(typeof(v.begin()) it=v.begin();it!=v.end();++it)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define sz size()
#define mkp make_pair
int _neg=0;
#define NEG return --_neg;
#define MOD 1000000007
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

void solve() {
	int n, m;;
	cin>>n>>m;
	int a[m][3];
	int c[n];
	REP(i, n) c[i] = 0;
	REP(i, m) {
		int aa, bb, cc;
		cin>>aa>>bb>>cc;
		aa--; bb--; cc--;
		int ia, ib, ic;
		if(c[aa]) ia = aa, ib = bb, ic = cc;
		else if(c[bb]) ia = bb, ib = aa, ic = cc;
		else if(c[cc]) ia = cc, ib = bb, ic = aa;
		else ia = -1;
		if(ia == -1) c[aa] = 1, c[bb] = 2, c[cc] = 3;
		else if(c[ia] == 1) c[ib] = 2, c[ic] = 3;
		else if(c[ia] == 2) c[ib] = 1, c[ic] = 3;
		else if(c[ia] == 3) c[ib] = 2, c[ic] = 1;
	}
	REP(i, n) cout<<c[i]<<" ";

}

int main() {
    while(1)
		solve();
	cout<<endl;

    /**/
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define RREP(i,n) RFOR(i, n-1, 0)
#define ECH(it, v) for(typeof(v.begin()) it=v.begin();it!=v.end();++it)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define sz size()
#define mkp make_pair
int _neg=0;
#define NEG return --_neg;
#define MOD 1000000007
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

void solve() {
	int n, m;;
	cin>>n>>m;
	int a[m][3];
	int c[n];
	REP(i, n) c[i] = 0;
	REP(i, m) {
		int aa, bb, cc;
		cin>>aa>>bb>>cc;
		aa--; bb--; cc--;
		int ia, ib, ic;
		if(c[aa]) ia = aa, ib = bb, ic = cc;
		else if(c[bb]) ia = bb, ib = aa, ic = cc;
		else if(c[cc]) ia = cc, ib = bb, ic = aa;
		else ia = -1;
		if(ia == -1) c[aa] = 1, c[bb] = 2, c[cc] = 3;
		else if(c[ia] == 1) c[ib] = 2, c[ic] = 3;
		else if(c[ia] == 2) c[ib] = 1, c[ic] = 3;
		else if(c[ia] == 3) c[ib] = 2, c[ic] = 1;
	}
	REP(i, n) cout<<c[i]<<" ";

}

int main() {
    x:
    solve();
	cout<<endl;

	goto x;
    /**/
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define RREP(i,n) RFOR(i, n-1, 0)
#define ECH(it, v) for(typeof(v.begin()) it=v.begin();it!=v.end();++it)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define sz size()
#define mkp make_pair
int _neg=0;
#define NEG return --_neg;
#define MOD 1000000007
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

void solve() {
	int n, m;;
	cin>>n>>m;
	int a[m][3];
	int c[n];
	REP(i, n) c[i] = 0;
	REP(i, m) {
		int aa, bb, cc;
		cin>>aa>>bb>>cc;
		aa--; bb--; cc--;
		int ia, ib, ic;
		if(c[aa]) ia = aa, ib = bb, ic = cc;
		else if(c[bb]) ia = bb, ib = aa, ic = cc;
		else if(c[cc]) ia = cc, ib = bb, ic = aa;
		else ia = -1;
		if(ia == -1) c[aa] = 1, c[bb] = 2, c[cc] = 3;
		else if(c[ia] == 1) c[ib] = 2, c[ic] = 3;
		else if(c[ia] == 2) c[ib] = 1, c[ic] = 3;
		else if(c[ia] == 3) c[ib] = 2, c[ic] = 1;
	}
	REP(i, n) cout<<c[i]<<" ";

}

int main() {
    x:
    solve();
	cout<<endl;

    /**/
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n+1];
    for(int i = 0; i < n; i++) a[i] = 0;
    for(int i = 0; i < m; i++){
        int b,c,d;
        cin >> b >> c >> d;
        if(a[c]) swap(b,c);
        if(a[d]) swap(b,c);
        if(!a[b]){
            a[b] = 1;
            a[c] = 2;
            a[d] = 3;
        } else {
            a[c] = (a[b])%3+1;
            a[d] = (a[b]+1)%3+1;
        }
    }
    for(int i = 1; i <= n; i++) cout << a[i] << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n+1];
    for(int i = 0; i < n; i++) a[i] = 0;
    for(int i = 0; i < m; i++){
        int b,c,d;
        cin >> b >> c >> d;
        if(a[c]) swap(b,c);
        if(a[d]) swap(b,d);
        if(!a[b]){
            a[b] = 1;
            a[c] = 2;
            a[d] = 3;
        } else {
            a[c] = (a[b])%3+1;
            a[d] = (a[b]+1)%3+1;
        }
    }
    for(int i = 1; i <= n; i++) cout << a[i] << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n+1];
    for(int i = 0; i < n; i++) a[i] = 0;
    for(int i = 0; i < m; i++){
        int b,c,d;
        cin >> b >> c >> d;
        if(a[c]) swap(b,c);
        if(a[d]) swap(b,c);
        if(!a[b]){
            a[b] = 1;
            a[c] = 2;
            a[d] = 3;
        } else {
            a[c] = (a[b]+1)%3;
            a[d] = (a[b]+2)%3;
        }
    }
    for(int i = 0; i < n; i++) cout << a[i] << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n+1];
    for(int i = 0; i < n; i++) a[i] = 0;
    for(int i = 0; i < m; i++){
        int b,c,d;
        cin >> b >> c >> d;
        if(a[c]) swap(b,c);
        if(a[d]) swap(b,c);
        if(!a[b]){
            a[b] = 1;
            a[c] = 2;
            a[d] = 3;
        } else {
            a[c] = (a[b])%3+1;
            a[d] = (a[b]+1)%3+1;
        }
    }
    for(int i = 0; i < n; i++) cout << a[i] << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n+1];
    for(int i = 0; i <= n; i++) a[i] = 0;
    for(int i = 0; i < m; i++){
        int b,c,d;
        cin >> b >> c >> d;
        if(a[c]) swap(b,c);
        if(a[d]) swap(b,d);
        if(a[b] == 0){
            a[b] = 1;
            a[c] = 2;
            a[d] = 3;
        } else {
            a[c] = (a[b])%3+1;
            a[d] = (a[b]+1)%3+1;
        }
    }
    for(int i = 1; i <= n; i++) cout << a[i] << " ";
    return 0;
}


#include <iostream>

using namespace std;

int main ()
{
    int a[100001] = {0};
    long int n, m;
    long int tmp1, tmp2, tmp3;
    cin >> n >> m;
    long int count = 1;
    for (long int i = 0; i < m; i++)
    {
        cin >> tmp1 >> tmp2 >> tmp3;
        if (a[tmp1] == 0)
        {
            a[tmp1] = count;
            count++;
            if (count > 3)
                count = 1;
        }
        if (a[tmp2] == 0)
        {
            a[tmp2] = count;
            count++;
            if (count > 3)
                count = 1;
        }
        if (a[tmp3] == 0)
        {
            a[tmp3] = count;
            count++;
            if (count > 3)
                count = 1;
        }
    }
    for (long int i = 1; i <= n; i++)
    {
        cout << a[i] << " ";
    }
    return 0;
}


#include <iostream>
//#include <cstdlib>
#include <cstring>

using namespace std;

void thulai (long int a, long int*b, long int*c)
{
    if (a == 1)
    {
        *b = 2;
        *c = 3;
    }
    else
    {
        if (a == 2)
        {
            *b = 1;
            *c = 3;
        }
        else
        {
            *b = 2;
            *c = 3;
        }
    }
}

int main()
{
    long int suit[100001] = {0};
    long int n, m, tmp1, tmp2, tmp3;
    cin >> n >> m;
    cin >> tmp1 >> tmp2 >> tmp3;
    suit[tmp1] = 1; suit[tmp2] = 2;  suit[tmp3] = 3;
    for (long int i = 2; i <= m; i++)
    {
        cin >> tmp1 >> tmp2 >> tmp3;
        if (suit[tmp1] != 0)
        {
            thulai (suit[tmp1], &suit[tmp2], &suit[tmp3]);
        }
        else
        {
            if (suit[tmp2] != 0)
            {
                thulai (suit[tmp2], &suit[tmp1], &suit[tmp3] );
            }
            else
            {
                if (suit[tmp3] != 0)
                {
                    thulai (suit[tmp3], &suit[tmp2], &suit[tmp1]);
                }
                else
                {
                    suit[tmp1] = 1;
                    suit[tmp2] = 2;
                    suit[tmp3] = 3;
                }
            }
        }
    }
    for (long int i = 1; i <= n; i++)
        cout << suit[i] << " ";
    return 0;
}


#include <iostream>
//#include <cstdlib>
#include <cstring>

using namespace std;

void thulai (long int a, long int*b, long int*c)
{
    if (a == 1)
    {
        *b = 2;
        *c = 3;
    }
    else
    {
        if (a == 2)
        {
            *b = 1;
            *c = 3;
        }
        else
        {
            *b = 1;
            *c = 2;
        }
    }
}

int main()
{
    long int suit[100001] = {0};
    long int n, m, tmp1, tmp2, tmp3;
    cin >> n >> m;
    cin >> tmp1 >> tmp2 >> tmp3;
    suit[tmp1] = 1; suit[tmp2] = 2;  suit[tmp3] = 3;
    for (long int i = 2; i <= m; i++)
    {
        cin >> tmp1 >> tmp2 >> tmp3;
        if (suit[tmp1] > 0 )
        {
            thulai (suit[tmp1], &suit[tmp2], &suit[tmp3]);
        }
        else
        {
            if (suit[tmp2] > 0)
            {
                thulai (suit[tmp2], &suit[tmp1], &suit[tmp3] );
            }
            else
            {
                if (suit[tmp3] > 0)
                {
                    thulai (suit[tmp3], &suit[tmp2], &suit[tmp1]);
                }
                else
                {
                    suit[tmp1] = 1;
                    suit[tmp2] = 2;
                    suit[tmp3] = 3;
                }
            }
        }
    }
    for (long int i = 1; i <= n; i++)
        cout << suit[i] << " ";
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define V vector
#define S String

#define iter(i, a)              for(typeof((a).begin()) i=(a).begin(); i!=(a).end(); i++)

typedef V<int>         vi;
typedef S<int>         si;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int main(void){
    int n, m;
    cin >> n >> m;

    int temp = m;
    vi clothes(n,0);

    int d1, d2, d3;

    set<int> c;

    while(temp--){

        c.insert(1); c.insert(2); c.insert(3);

        cin >> d1 >> d2 >> d3;

        set<int> people;
        people.insert(d1);
        people.insert(d2);
        people.insert(d3);

        iter(it, people)
        {
            if(c.find(clothes[*it-1]) != c.end())
                c.erase(clothes[*it-1]);
        }

        iter(it, people){
            if(clothes[*it-1] == 0){
                clothes[*it-1] = *(c.begin());
                c.erase(*(c.begin()));
            }
        }

    }

    for(vi::iterator it = clothes.begin(); it != clothes.end(); ++it)
        cout << *it << " ";

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define V vector

typedef V<int>         vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int main(void){
    int n, m;
    cin >> n >> m;

    int temp = m;
    vi clothes(n,0);

    int d1, d2, d3;

    set<int> c;

    while(temp--){

        c.insert(1); c.insert(2); c.insert(3);

        cin >> d1 >> d2 >> d3;

        set<int> people;
        people.insert(d1);
        people.insert(d2);
        people.insert(d3);

        for(set<int>::iterator it = people.begin(); it != people.end(); ++it)
        {
            if(c.find(clothes[*it-1]) != c.end())
                c.erase(clothes[*it-1]);
        }

        for(set<int>::iterator it = people.begin(); it != people.end(); ++it){
            if(clothes[*it-1] == 0){
                clothes[*it-1] = *(c.begin());
                c.erase(*(c.begin()));
            }
        }

    }

    for(vi::iterator it = clothes.begin(); it != clothes.end(); ++it)
        cout << *it << " ";

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define V vector
#define S String

#define iter(i, a)              for(typeof((a).begin()) i=(a).begin(); i!=(a).end(); i++)

typedef V<int>         vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int main(void){
    int n, m;
    cin >> n >> m;

    int temp = m;
    vi clothes(n,0);

    int d1, d2, d3;

    set<int> c;

    while(temp--){

        c.insert(1); c.insert(2); c.insert(3);

        cin >> d1 >> d2 >> d3;

        set<int> people;
        people.insert(d1);
        people.insert(d2);
        people.insert(d3);

        iter(it, people)
        {
            if(c.find(clothes[*it-1]) != c.end())
                c.erase(clothes[*it-1]);
        }

        iter(it, people){
            if(clothes[*it-1] == 0){
                clothes[*it-1] = *(c.begin());
                c.erase(*(c.begin()));
            }
        }

    }

    iter(it, clothes)
        cout << *it << " ";

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define V vector
#define S String

#define iter(i, a)              for(typeof((a).begin()) i=(a).begin(); i!=(a).end(); i++)

typedef V<int>         vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int main(void){
    int n, m;
    cin >> n >> m;

    int temp = m;
    vi clothes(n,0);

    int d1, d2, d3;

    set<int> c;

    while(temp--){

        c.insert(1); c.insert(2); c.insert(3);

        cin >> d1 >> d2 >> d3;

        set<int> people;
        people.insert(d1);
        people.insert(d2);
        people.insert(d3);

        iter(it, people)
        {
            if(c.find(clothes[*it-1]) != c.end())
                c.erase(clothes[*it-1]);
        }

        iter(it, people){
            if(clothes[*it-1] == 0){
                clothes[*it-1] = *(c.begin());
                c.erase(*(c.begin()));
            }
        }

    }

    for(vi::iterator it = clothes.begin(); it != clothes.end(); ++it)
        cout << *it << " ";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stdio.h>

#define N 100005

using namespace std;

int n, m;
int a[N];
vector<int> v[N];
bool t[4][N];

int main() {

//	freopen("a.in","r", stdin);
//	freopen("a.out","w", stdout);

	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		v[x].push_back(i);
		v[y].push_back(i);
		v[z].push_back(i);
	}

	for (int i = 1; i <= n; i++)
	{
		int col = 1;
		while (col <= 2)
		{
			bool notneed = 0;
			for (int j = 0; j < v[i].size(); j++)
				notneed = notneed || t[col][v[i][j]];

			if (notneed) col++;
			else
			{
				a[i] = col;
				for (int j = 0; j < v[i].size(); j++)
					t[col][v[i][j]] = 1;
				break;
			}
		}
		cout << col << " ";
	}

return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stdio.h>

#define N 100005

using namespace std;

int n, m;
int a[N];
vector<int> v[N];
bool t[4][N];

int main() {

//	freopen("a.in","r", stdin);
//	freopen("a.out","w", stdout);

	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		v[x].push_back(i);
		v[y].push_back(i);
		v[z].push_back(i);
	}

	for (int i = 1; i <= m; i++)
	{
		int col = 1;
		while (col <= 2)
		{
			bool notneed = 0;
			for (int j = 0; j < v[i].size(); j++)
				notneed = notneed || t[col][v[i][j]];

			if (notneed) col++;
			else
			{
				a[i] = col;
				for (int j = 0; j < v[i].size(); j++)
					t[col][v[i][j]] = 1;
				break;
			}
		}
		cout << col << " ";
	}

return 0;
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;vector<int>dsu;
int n,m,d,i,fa[M],x[M],y[M],used[M],vi[M],Fa,u,v;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}
int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(x[i]!=1&&y[i]!=1)merge(x[i],y[i]);
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    for(i=0;i<g[1].size();i++){
        u=g[1][i];
        Fa=fin(u);
        if(!used[Fa]){
            dsu.push_back(u);
            Q.push(u);
            vi[u]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();
    for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }
    while(!Q.empty()){
        u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;vector<int>dsu;
int n,m,d,i,fa[M],x[M],y[M],used[M],vi[M],Fa;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}
int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(x[i]!=1&&y[i]!=1)merge(x[i],y[i]);
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    for(i=1;i<=n;i++){
        Fa=fin(i);
        if(!used[Fa]){
            dsu.push_back(Fa);
            Q.push(Fa);
            vi[Fa]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();
    for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            int v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;vector<int>dsu;
int n,m,d,i,fa[M],x[M],y[M],used[M],vi[M],Fa,u,v;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}
int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(x[i]!=1&&y[i]!=1)merge(x[i],y[i]);
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    for(i=0;i<g[1].size();i++){
        u=g[1][i];
        Fa=fin(u);
        if(!used[Fa]){
            dsu.push_back(Fa);
            Q.push(Fa);
            vi[Fa]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();
    for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }
    while(!Q.empty()){
        u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;vector<int>dsu;
int n,m,d,i,fa[M],x[M],y[M],used[M],vi[M],Fa;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}
int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(x[i]!=1&&y[i]!=1)merge(x[i],y[i]);
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    for(i=2;i<=n;i++){
        Fa=fin(i);
        if(!used[Fa]){
            dsu.push_back(Fa);
            Q.push(Fa);
            vi[Fa]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();
    for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            int v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;
vector<int>dsu;
int n,m,d,i,fa[M],x,y,used[M],vi[M],Fa,u,v;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}

int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        if(x!=1&&y!=1)merge(x,y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(i=0;i<g[1].size();i++){
        u=g[1][i];
        Fa=fin(u);
        if(!used[Fa]){
            dsu.push_back(u);
            Q.push(u);
            vi[u]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();

    /*for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }*/
    for(i=0;i<g[1].size();i++){
        if(d==0)break;
        u=g[1][i];
        if(!vi[u]){
            vi[u]=1;
            Q.push(u);
            printf("1 %d\n",u);
            d--;
        }
    }
    while(!Q.empty()){
        u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


#include<bits/stdc++.h>
#define M 200005
using namespace std;
queue<int>Q;vector<int>dsu;
int n,m,d,i,fa[M],x[M],y[M],used[M],vi[M],Fa;
vector<int>g[M];
int fin(int u){return fa[u]==u?u:fa[u]=fin(fa[u]);}

void merge(int u,int v){
    int X=fin(u),Y=fin(v);
    if(X!=Y)fa[X]=Y;
}
int main(){
    cin>>n>>m>>d;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(x[i]==1||y[i]==1)merge(x[i],y[i]);
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    for(i=1;i<=n;i++){
        Fa=fin(i);
        if(!used[Fa]){
            dsu.push_back(Fa);
            Q.push(Fa);
            vi[Fa]=1;
            used[Fa]=1;
        }
    }
    if(d<dsu.size()||g[1].size()<d){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    vi[1]=1;
    for(i=0;i<dsu.size();i++)
        printf("1 %d\n",dsu[i]);
    d-=dsu.size();
    for(i=2;i<=n;i++){
        if(d==0)break;
        if(!vi[i]){
            vi[i]=1;
            Q.push(i);
            printf("1 %d\n",i);
            d--;
        }
    }
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(i=0;i<g[u].size();i++){
            int v=g[u][i];
            if(vi[v])continue;
            vi[v]=1;
            printf("%d %d\n",u,v);
            Q.push(v);
        }
    }
}


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

typedef long long ll;

struct Dsu {
  vector<int> anc, size;
  Dsu(int n = 0) : anc(n), size(n, 0) {
    iota(anc.begin(), anc.end(), 0);
  }
  int operator[] (int x) {
    return x == anc[x] ? x : anc[x] = operator[](anc[x]);
  }
  bool operator() (int u, int v) {
    int a = operator[](u), b = operator[](v);
    if (a == b) return false;
    if (size[a] < size[b]) anc[a] = b;
    else anc[b] = a, size[a] += (size[a] == size[b]);
    return true;
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, d; cin >> n >> m >> d;
  vector<vector<int>> G(n);
  while (m--) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  Dsu D(n);
  for (int i = 1; i < n; i++) {
    if (D[i] == i) {
      queue<int> Q; Q.push(i);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (auto& v : G[u]) {
          if (v != 0 && D(u, v)) {
            Q.push(v);
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += (D[i] == i);
  }
  if (cnt > d || (int)G[0].size() < d) {
    cout << "NO\n";
    return 0;
  }
  vector<pair<int, int>> ans;
  for (auto& v : G[0]) {
    if (D[v] == v) {
      ans.push_back({ 0, v });
    }
  }
  if ((int)ans.size() < d) {
    for (auto& v : G[0]) {
      if (D[v] != v) {
        ans.push_back({ 0, v });
      }
      if ((int)ans.size() == d) {
        break;
      }
    }
  }
  queue<int> Q;
  for (auto& x : ans) {
    Q.push(x.second);
  }
  D = Dsu(n);
  for (auto& x : ans) {
    D(x.first, x.second);
  }
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& v : G[u]) {
      if (v != 0 && D(u, v)) {
        ans.push_back({ u, v });
        Q.push(v);
      }
    }
  }
  assert((int)ans.size() == n - 1);
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << "\n";
  }
}


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

typedef long long ll;

struct Dsu {
  vector<int> anc, size;
  Dsu(int n = 0) : anc(n), size(n, 0) {
		iota(anc.begin(), anc.end(), 0);
  }
  int operator[] (int x) {
    return x == anc[x] ? x : anc[x] = operator[](anc[x]);
  }
  bool operator() (int u, int v) {
    int a = operator[](u), b = operator[](v);
    if (a == b) return false;
    if (size[a] < size[b]) anc[a] = b;
    else anc[b] = a, size[a] += (size[a] == size[b]);
    return true;
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, d; cin >> n >> m >> d;
  vector<vector<int>> G(n);
  while (m--) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  Dsu D(n);
  for (int i = 1; i < n; i++) {
    if (D[i] == i) {
      queue<int> Q; Q.push(i);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (auto& v : G[u]) {
          if (v != 0 && D(u, v)) {
            Q.push(v);
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += (D[i] == i);
  }
  if (cnt > d || (int)G[0].size() < d) {
    cout << "NO\n";
    return 0;
  }
  vector<pair<int, int>> ans;
  for (auto& v : G[0]) {
    if (D[v] == v) {
      ans.push_back({ 0, v });
    }
  }
  if ((int)ans.size() < d) {
    for (auto& v : G[0]) {
      if (D[v] != v) {
        ans.push_back({ 0, v });
      }
      if ((int)ans.size() == d) {
        break;
      }
    }
  }
  queue<int> Q;
  for (auto& x : ans) {
    Q.push(x.second);
  }
  D = Dsu(n);
  for (auto& x : ans) {
    D(x.first, x.second);
  }
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& v : G[u]) {
      if (v != 0 && D(u, v)) {
        ans.push_back({ u, v });
        Q.push(v);
      }
    }
  }
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << "\n";
  }
}


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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, D; cin >> n >> m >> D;
  vector<vector<int>> G(n);
  while (m--) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<int> anc(n);
  iota(anc.begin(), anc.end(), 0);
  function<int(int)> find = [&](int x) {
    return x == anc[x] ? x : anc[x] = find(anc[x]);
  };
  for (int i = 1; i < n; i++) {
    if (find(i) == i) {
      queue<int> Q; Q.push(i);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (auto& v : G[u]) {
          if (v > 0 && find(v) != i) {
            anc[v] = i;
            Q.push(v);
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += (find(i) == i);
  }
  if (cnt > D || (int)G[0].size() < D) {
    cout << "NO\n";
    return 0;
  }
  queue<int> Q;
  vector<int> vis(n, 0), vvis(n, 0);
  vector<pair<int, int>> ans;
  for (auto& v : G[0]) {
    if (!vvis[find(v)]) {
      ans.push_back({ 0, v });
      vvis[find(v)] = 1;
      vis[v] = 1;
      --D;
    }
  }
  vis[0] = 1;
  for (int i = 1; i < n; i++) {
    if (vis[i]) {
      Q.push(i);
    }
  }
  if (D > 0) {
    for (auto& v : G[0]) {
      if (!vis[v]) {
        Q.push(v);
        ans.push_back({ 0, v });
        vis[v] = 1;
        --D;
      }
    }
  }
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& v : G[u]) {
      if (!vis[v]) {
        Q.push(v);
        vis[v] = 1;
        ans.push_back({ u, v });
      }
    }
  }
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << "\n";
  }
}


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

typedef long long ll;

struct Dsu {
  vector<int> anc, size;
  Dsu(int n = 0) : anc(n), size(n, 0) {
    iota(anc.begin(), anc.end(), 0);
  }
  int operator[] (int x) {
    return x == anc[x] ? x : anc[x] = operator[](anc[x]);
  }
  bool operator() (int u, int v) {
    int a = operator[](u), b = operator[](v);
    if (a == b) return false;
    if (size[a] < size[b]) anc[a] = b;
    else anc[b] = a, size[a] += (size[a] == size[b]);
    return true;
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, d; cin >> n >> m >> d;
  vector<vector<int>> G(n);
  while (m--) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  Dsu D(n);
  for (int i = 1; i < n; i++) {
    if (D[i] == i) {
      queue<int> Q; Q.push(i);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (auto& v : G[u]) {
          if (v != 0 && D(u, v)) {
            Q.push(v);
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += (D[i] == i);
  }
  if (cnt > d || (int)G[0].size() < d) {
    cout << "NO\n";
    return 0;
  }
  vector<pair<int, int>> ans;
  for (auto& v : G[0]) {
    if (D[v] == v) {
      ans.push_back({ 0, v });
    }
  }
  if ((int)ans.size() < d) {
    for (auto& v : G[0]) {
      if (D[v] != v) {
        ans.push_back({ 0, v });
      }
      if ((int)ans.size() == d) {
        break;
      }
    }
  }
  queue<int> Q;
  vector<int> vis(n, 0); vis[0] = 1;
  for (auto& x : ans) {
    Q.push(x.second);
    vis[x.second] = 1;
  }
  D = Dsu(n);
  for (auto& x : ans) {
    D(x.first, x.second);
  }
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& v : G[u]) {
      if (!vis[v]) {
        Q.push(v), vis[v] = 1;
        if (D(u, v)) {
          ans.push_back({ u, v });
        }
      }
    }
  }
  assert((int)ans.size() == n - 1);
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << "\n";
  }
}


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

typedef long long ll;

struct Dsu {
  vector<int> anc;
  Dsu(int n = 0) : anc(n) {
    iota(anc.begin(), anc.end(), 0);
  }
  int operator[] (int x) {
    return x == anc[x] ? x : anc[x] = operator[](anc[x]);
  }
  bool operator() (int u, int v) {
    int a = operator[](u), b = operator[](v);
    if (a == b) return false;
    return (anc[b] = a), true;
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, d; cin >> n >> m >> d;
  vector<vector<int>> G(n);
  while (m--) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  Dsu D(n);
  for (int i = 1; i < n; i++) {
    if (D[i] == i) {
      queue<int> Q; Q.push(i);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (auto& v : G[u]) {
          if (v != 0 && D(u, v)) {
            Q.push(v);
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += (D[i] == i);
  }
  if (cnt > d || (int)G[0].size() < d) {
    cout << "NO\n";
    return 0;
  }
  vector<pair<int, int>> ans;
  for (auto& v : G[0]) {
    if (D[v] == v) {
      ans.push_back({ 0, v });
    }
  }
  if ((int)ans.size() < d) {
    for (auto& v : G[0]) {
      if (D[v] != v) {
        ans.push_back({ 0, v });
      }
      if ((int)ans.size() == d) {
        break;
      }
    }
  }
  queue<int> Q;
  vector<int> vis(n, 0); vis[0] = 1;
  for (auto& x : ans) {
    Q.push(x.second);
    vis[x.second] = 1;
  }
  D = Dsu(n);
  for (auto& x : ans) {
    D(x.first, x.second);
  }
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (auto& v : G[u]) {
      if (!vis[v]) {
        Q.push(v), vis[v] = 1;
        if (D(u, v)) {
          ans.push_back({ u, v });
        }
      }
    }
  }
  assert((int)ans.size() == n - 1);
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << "\n";
  }
}


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

typedef long long ll;

struct Dsu {
  vector<int> anc;
  Dsu(int n = 0) : anc(n) {
    iota(anc.begin(), anc.end(), 0);
  }
  int operator[] (int x) {
    return x == anc[x] ? x : anc[x] = operator[](anc[x]);
  }
  bool operator() (int u, int v) {
    int a = operator[](u), b = operator[](v);
    if (a == b) return false;
    return (anc[b] = a), true;
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m, d; cin >> n >> m >> d;
  vector<int> u(m), v(m), deg(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i];
    --u[i], --v[i];
    ++deg[u[i]], ++deg[v[i]];
  }
  Dsu chk(n);
  for (int i = 0; i < m; i++) {
    if (!u[i] || !v[i]) {
      continue;
    }
    chk(u[i], v[i]);
  }
  int counter = 0;
  for (int i = 1; i < n; i++) {
    counter += (chk[i] == i);
  }
  if (counter > d || deg[0] < d) {
    cout << "NO\n";
    return 0;
  }
  Dsu D(n);
  vector<pair<int, int>> ans;
  for (int i = 0; d > 0 && i < m; i++) {
    if ((!u[i] || !v[i]) && chk(u[i], v[i])) {
      ans.push_back({ u[i] + 1, v[i] + 1 });
      D(u[i], v[i]);
      --d;
    }
  }
  for (int i = 0; d > 0 && i < m; i++) {
    if ((!u[i] || !v[i]) && D(u[i], v[i])) {
      ans.push_back({ u[i] + 1, v[i] + 1 });
      --d;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!u[i] || !v[i]) {
      continue;
    }
    if (D(u[i], v[i])) {
      ans.push_back({ u[i] + 1, v[i] + 1 });
    }
  }
  assert((int)ans.size() == n - 1);
  cout << "YES\n";
  for (auto& x : ans) {
    cout << x.first << " " << x.second << "\n";
  }
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m, d;
    cin >> n >> m >> d;

    vector <int> edges[n];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    if (edges[0].size() < d) {
        cout << "NO\n";
        return 0;
    }

    int cnt = 0;
    for (int to : edges[0]) {
        if (edges[to].size() > 1) cnt++;
    }

    if (cnt < d) {
        cout << "NO\n";
        return 0;
    }

    cout << "YES\n";

    vector <bool> visited(n, false);
    queue <int> q;
    visited[0] = true;

    cnt = 0;
    for (int to : edges[0]) {
        if (cnt >= d) break;
        if (edges[to].size() > 1) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m, d;
    cin >> n >> m >> d;

    UnionFind uf(n);
    vector <int> edges[n];
    vector <bool> connect_first(n, false);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);

        if (u == 0) connect_first[v] = true;
        if (v == 0) connect_first[u] = true;
    }

    for (int i = 1; i < n; i++) {
        if (connect_first[i]) {
            for (int to : edges[i]) {
                if (to == 0) continue;
                uf.unite(i, to);
            }
        }
    }

    for (int i = 1; i < n; i++) {
        if (!connect_first[i]) {
            for (int to : edges[i]) {
                uf.unite(i, to);
            }
        }
    }

    if (edges[0].size() < d) {
        cout << "NO\n";
        return 0;
    }

    int cnt = 0;
    for (int to : edges[0]) {
        int par = uf.find(to);
        if (par == to) cnt++;
    }

    if (cnt > d) {
        cout << "NO\n";
        return 0;
    }

    cout << "YES\n";

    vector <bool> visited(n, false);
    queue <int> q;
    visited[0] = true;

    cnt = 0;
    for (int to : edges[0]) {
        int par = uf.find(to);
        if (par == to) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    for (int to : edges[0]) {
        if (cnt == d) break;

        int par = uf.find(to);
        if (par != to) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();
        if (visited[from]) continue;

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m, d;
    cin >> n >> m >> d;

    vector <int> edges[n];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    if (edges[0].size() < d) {
        cout << "NO\n";
        return 0;
    }

    int cnt = 0;
    for (int to : edges[0]) {
        if (edges[to].size() == 1) cnt++;
    }

    if (cnt > d) {
        cout << "NO\n";
        return 0;
    }

    cout << "YES\n";

    vector <bool> visited(n, false);
    queue <int> q;
    visited[0] = true;

    cnt = 0;
    for (int to : edges[0]) {
        if (edges[to].size() == 1) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    for (int to : edges[0]) {
        if (cnt == d) break;
        if (edges[to].size() > 1) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int n, m, d, u, v;
vector <int> edges[200005];
bool visited[200005];
bool connected_first[200005];

void dfs(int from) {
    for (int to : edges[from]) {
        if (visited[to]) continue;
        visited[to] = true;
        if (from == 0) connected_first[to] = true;
        dfs(to);
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> d;

    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    if (edges[0].size() < d) {
        cout << "NO\n";
        return 0;
    }

    visited[0] = true;
    dfs(0);

    fill(visited, visited+n, false);
    visited[0] = true;
    queue <int> q;
    int cnt = 0;

    for (int to : edges[0]) {
        if (connected_first[to]) {
            q.push(to);
            cout << 1 << " " << to + 1 << '\n';
            visited[to] = true;
            cnt++;
        }
    }

    if (cnt > d) {
        cout << "NO\n";
        return 0;
    }

    for (int to : edges[0]) {
        if (cnt == d) break;
        if (!connected_first[to]) {
            q.push(to);
            cout << 1 << " " << to + 1 << '\n';
            visited[to] = true;
            cnt++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int n, m, d, u, v, c;
vector <int> edges[200005];
bool visited[200005];
bool connected_first[200005];

void dfs(int from) {
    for (int to : edges[from]) {
        if (visited[to]) continue;
        visited[to] = true;
        if (from == 0) {
            connected_first[to] = true;
            c++;
        }
        dfs(to);
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> d;

    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    visited[0] = true;
    c = 0;
    dfs(0);

    if (edges[0].size() < d || c > d) {
        cout << "NO\n";
        return 0;
    }

    fill(visited, visited+n, false);
    visited[0] = true;
    queue <int> q;

    cout << "YES\n";
    for (int to : edges[0]) {
        if (connected_first[to]) {
            q.push(to);
            cout << 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    for (int to : edges[0]) {
        if (c == d) break;
        if (!connected_first[to]) {
            q.push(to);
            cout << 1 << " " << to + 1 << '\n';
            visited[to] = true;
            c++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m, d;
    cin >> n >> m >> d;

    UnionFind uf(n);
    vector <int> edges[n];
    vector <bool> connect_first(n, false);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);

        if (u == 0) connect_first[v] = true;
        if (v == 0) connect_first[u] = true;
    }

    for (int i = 1; i < n; i++) {
        if (connect_first[i]) {
            for (int to : edges[i]) {
                if (to == 0) continue;
                uf.unite(i, to);
            }
        }
    }

    for (int i = 1; i < n; i++) {
        if (!connect_first[i]) {
            for (int to : edges[i]) {
                uf.unite(i, to);
            }
        }
    }

    if (edges[0].size() < d) {
        cout << "NO\n";
        return 0;
    }

    int cnt = 0;
    for (int to : edges[0]) {
        int par = uf.find(to);
        if (par == to) cnt++;
    }

    if (cnt > d) {
        cout << "NO\n";
        return 0;
    }

    cout << "YES\n";

    vector <bool> visited(n, false);
    queue <int> q;
    visited[0] = true;

    cnt = 0;
    for (int to : edges[0]) {
        int par = uf.find(to);
        if (par == to) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    for (int to : edges[0]) {
        if (cnt == d) break;

        int par = uf.find(to);
        if (par != to) {
            cout << 1 << " " << to + 1 << "\n";
            q.push(to);
            visited[to] = true;
            cnt++;
        }
    }

    while (q.size()) {
        int from = q.front();
        q.pop();

        for (int to : edges[from]) {
            if (visited[to]) continue;
            q.push(to);
            cout << from + 1 << " " << to + 1 << '\n';
            visited[to] = true;
        }
    }

    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void bad() { cout << "NO" ; line ; exit ( 0 ) ; }

const int N = 2e5 + 10 ;

int n , m , opt_d ;
vpii ed ;

int deg[N] ;

vi parent ( N , -1 ) ;

void read()
{
    cin >> n >> m >> opt_d ;

    ed.resize ( m ) ;
    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ; b -- ;

        deg[a] ++ ;
        deg[b] ++ ;

        ed[i] = { a , b } ;
    }
}

vpii ans_ed ;
int z = 0 ;
bool ok = false ;

int find_parent ( int indx )
{
    if ( parent[indx] < 0 )
        return indx ;

    return parent[indx] = find_parent ( parent[indx] ) ;
}

void join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return ;

    ans_ed.pb ( { a , b } ) ;
    z ++ ;

    if ( z == n - 1 ) /// This improves the Worst case performance of any Spanning tree algo. We may stop as soon as we have found n-1 edges
    {
        ok = true ;
        return ;
    }

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;
}

void join_all_edges_with_node_1()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 )
        {
            join ( a , b ) ;
            deg[0] -- ;

            if ( ok ) return ;
            if ( deg[0] == 0 ) return ;
        }
    }
}

void join_all_other_edges()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 ) C ;

        join ( a , b ) ;
        if ( ok ) return ;
    }
}

void solve ( int test_case )
{
    read() ;

    if ( deg[0] < opt_d ) bad() ;

    deg[0] = opt_d ;
    join_all_edges_with_node_1() ;

    if ( ok == false )
        join_all_other_edges() ;

    if ( z != n - 1 ) bad() ;

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

    if ( conn != 1 ) bad() ;

    cerr << "\nmy ans : \n" ;

    cout << "YES" ; line ;
    for ( auto i : ans_ed )
        cout << i.F + 1 << " " << i.S + 1 , line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void bad() { cout << "NO" ; line ; exit ( 0 ) ; }

const int N = 2e5 + 10 ;
vi g[N] ;

int n , m , opt_d ;

vpii ed ;
vi parent ( N , -1 ) ;

int find_parent ( int node )
{
    if ( parent[node] < 0 )
        return node ;

    return parent[node] = find_parent ( parent[node] ) ;
}

bool join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return false ;

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;

    return true ;
}

void read()
{
    cin >> n >> m >> opt_d ;

    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        if ( a > b ) swap ( a , b ) ;
        a -- ; b -- ;

        if ( a == 0 )
            ed.pb ( { a , b } ) ;

        else
        {
            g[a].pb ( b ) ;
            g[b].pb ( a ) ;

            join ( a , b ) ;
        }
    }
}

bool vis[N] ;

void bfs ( int node )
{
    queue < int > q ;
    q.push ( node ) ;
    vis[node] = 1 ;

    cerr << "\n" ;
    cout << "YES" ; line ;
    int edge = n - 1 ;

    while ( q.empty() == false )
    {
        node = q.front() ;
        q.pop() ;

        for ( auto &i : g[node] )
        {
            if ( vis[i] ) C ;

            cout << node + 1 << " " << i + 1 ;
            line ;

            edge -- ;

            q.push ( i ) ;
            vis[i] = 1 ;

            if ( edge == 0 )
                exit ( 0 ) ;
        }
    }
}

void solve ( int test_case )
{
    read() ;

    int con = -1 ;
    for ( int i=0 ; i < n ; i ++ )
    {
        con += ( parent[i] < 0 ) ;
    }

    int bak = con ;
    int z = ed.size() ;

    if ( opt_d > z ) bad() ;

    vb taken_edge ( z ) ;

    for ( int i=0 ; i < z && con != 0 ; i ++ )
    {
        int a = ed[i].F ;
        int b = ed[i].S ;

        bool ver = join ( a , b ) ;

        if ( ver )
        {
            con -- ;
            taken_edge[i] = 1 ;

            g[a].pb ( b ) ;
            g[b].pb ( a ) ;
        }
    }

    bak -= opt_d ;

    for ( int i=0 ; i < z && bak != 0 ; i ++ )
    {
        if ( taken_edge[i] ) C ;

        int a = ed[i].F ;
        int b = ed[i].S ;

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

        bak -- ;
    }

    bfs ( 0 ) ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


/// https://codeforces.com/contest/1133/problem/F2

/// Mistakes -

/// 1 : I did optimization in Kruskal ; that as soon as I get n-1 edges ; I terminate the process of adding edges
/// However I wrote that line on the wrong place ( Before performing merge operation in DSU ) ; thus number of
/// connected components later was not correct ; and I had to check whether I have got a correct MST or not
/// ( Number of connected components had to be 1 )

/// Mistake 2 -

/// I randomly merged first opt_d edges with the node 1. Because of this ; if let say some vertex was connected
/// only to vertex 1 ; and this came later than opt_d vertices in edge order ; then this vertex will never be
/// included in the MST ; and thus we will get WA ( I will be printing a NO ; while answer is possible )

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void bad() { cout << "NO" ; line ; exit ( 0 ) ; }

const int N = 2e5 + 10 ;

int n , m , opt_d ;
vpii ed ;

int deg[N] ;

vi parent ( N , -1 ) ;

void read()
{
    cin >> n >> m >> opt_d ;

    ed.resize ( m ) ;
    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ; b -- ;

        deg[a] ++ ;
        deg[b] ++ ;

        ed[i] = { a , b } ;
    }
}

vpii ans_ed ;
int z = 0 ;
bool ok = false ;

int find_parent ( int indx )
{
    if ( parent[indx] < 0 )
        return indx ;

    return parent[indx] = find_parent ( parent[indx] ) ;
}

void join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return ;

    ans_ed.pb ( { a , b } ) ;
    z ++ ;

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;

    if ( z == n - 1 ) /// This improves the Worst case performance of any Spanning tree algo. We may stop as soon as we have found n-1 edges
    {
        ok = true ;
        return ;
    }

}

bool comp ( pii &a , pii &b )
{
    int d1 = deg[a.S] ;
    int d2 = deg[b.S] ;

    if ( d1 < d2 )
        return true ;

    return false ;
}

void join_all_edges_with_node_1()
{
    vpii to_join ;

    for ( auto &i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 )
        {
            if ( a != 0 ) swap ( a , b ) ;
            to_join.pb ( { a , b } ) ;
        }
    }

    sort ( allcomp ( to_join ) ) ;

    for ( auto &i : to_join )
    {
        join ( i.F , i.S ) ;
        deg[0] -- ;

        if ( ok ) return ;
        if ( deg[0] == 0 ) return ;
    }
}

void join_all_other_edges()
{
    for ( auto &i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 ) C ;

        join ( a , b ) ;
        if ( ok ) return ;
    }
}

void solve ( int test_case )
{
    read() ;

    if ( deg[0] < opt_d ) bad() ;

    deg[0] = opt_d ;
    join_all_edges_with_node_1() ;

    if ( ok == false )
        join_all_other_edges() ;

    if ( z != n - 1 ) bad() ;

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

    if ( conn != 1 ) bad() ;

    cerr << "\nmy ans : \n" ;

    cout << "YES" ; line ;
    for ( auto i : ans_ed )
        cout << i.F + 1 << " " << i.S + 1 , line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

const int N = 2e5 + 10 ;

int n , m , opt_d ;
vpii ed ;

int deg[N] ;

vi parent ( N , -1 ) ;

void read()
{
    cin >> n >> m >> opt_d ;

    ed.resize ( m ) ;
    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ; b -- ;

        deg[a] ++ ;
        deg[b] ++ ;

        ed[i] = { a , b } ;
    }
}

vpii ans_ed ;
int z = 0 ;
bool ok = false ;

int find_parent ( int indx )
{
    if ( parent[indx] < 0 )
        return indx ;

    return parent[indx] = find_parent ( parent[indx] ) ;
}

void join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return ;

    ans_ed.pb ( { a , b } ) ;
    z ++ ;

    if ( z == n - 1 ) /// This improves the Worst case performance of any Spanning tree algo. We may stop as soon as we have found n-1 edges
    {
        ok = true ;
        return ;
    }

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;
}

void join_all_edges_with_node_1()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 )
        {
            join ( a , b ) ;
            deg[0] -- ;

            if ( ok ) return ;
            if ( deg[0] == 0 ) return ;
        }
    }
}

void join_all_other_edges()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 ) C ;

        join ( a , b ) ;
        if ( ok ) return ;
    }
}

void solve ( int test_case )
{
    read() ;

    if ( deg[0] < opt_d ) { cout << "NO" ; line ; return ; }

    deg[0] = opt_d ;
    join_all_edges_with_node_1() ;

    if ( ok == false )
        join_all_other_edges() ;

    cerr << "\nmy ans : \n" ;

    cout << "YES" ; line ;
    for ( auto i : ans_ed )
        cout << i.F + 1 << " " << i.S + 1 , line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void bad() { cout << "NO" ; line ; exit ( 0 ) ; }

const int N = 2e5 + 10 ;

int n , m , opt_d ;
vpii ed ;

int deg[N] ;

vi parent ( N , -1 ) ;

void read()
{
    cin >> n >> m >> opt_d ;

    ed.resize ( m ) ;
    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ; b -- ;

        deg[a] ++ ;
        deg[b] ++ ;

        ed[i] = { a , b } ;
    }
}

vpii ans_ed ;
int z = 0 ;
bool ok = false ;

int find_parent ( int indx )
{
    if ( parent[indx] < 0 )
        return indx ;

    return parent[indx] = find_parent ( parent[indx] ) ;
}

void join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return ;

    ans_ed.pb ( { a , b } ) ;
    z ++ ;

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;

    if ( z == n - 1 ) /// This improves the Worst case performance of any Spanning tree algo. We may stop as soon as we have found n-1 edges
    {
        ok = true ;
        return ;
    }

}

void join_all_edges_with_node_1()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 )
        {
            join ( a , b ) ;
            deg[0] -- ;

            if ( ok ) return ;
            if ( deg[0] == 0 ) return ;
        }
    }
}

void join_all_other_edges()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 ) C ;

        join ( a , b ) ;
        if ( ok ) return ;
    }
}

void solve ( int test_case )
{
    read() ;

    if ( deg[0] < opt_d ) bad() ;

    deg[0] = opt_d ;
    join_all_edges_with_node_1() ;

    if ( ok == false )
        join_all_other_edges() ;

    if ( z != n - 1 ) bad() ;

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

    if ( conn != 1 ) bad() ;

    cerr << "\nmy ans : \n" ;

    cout << "YES" ; line ;
    for ( auto i : ans_ed )
        cout << i.F + 1 << " " << i.S + 1 , line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void bad() { cout << "NO" ; line ; exit ( 0 ) ; }

const int N = 2e5 + 10 ;
vi g[N] ;

int n , m , opt_d ;

vpii ed ;
vi parent ( N , -1 ) ;

int find_parent ( int node )
{
    if ( parent[node] < 0 )
        return node ;

    return parent[node] = find_parent ( parent[node] ) ;
}

bool join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return false ;

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;

    return true ;
}

void read()
{
    cin >> n >> m >> opt_d ;

    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        if ( a > b ) swap ( a , b ) ;
        a -- ; b -- ;

        if ( a == 0 )
            ed.pb ( { a , b } ) ;

        else
        {
            g[a].pb ( b ) ;
            g[b].pb ( a ) ;

            join ( a , b ) ;
        }
    }
}

bool vis[N] ;

void bfs ( int node )
{
    queue < int > q ;
    q.push ( node ) ;
    vis[node] = 1 ;

    cerr << "\n" ;
    cout << "YES" ; line ;
    int edge = n - 1 ;

    while ( q.empty() == false )
    {
        node = q.front() ;
        q.pop() ;

        for ( auto &i : g[node] )
        {
            if ( vis[i] ) C ;

            cout << node + 1 << " " << i + 1 ;
            line ;

            edge -- ;

            q.push ( i ) ;
            vis[i] = 1 ;

            if ( edge == 0 )
                exit ( 0 ) ;
        }
    }
}

void solve ( int test_case )
{
    read() ;

    int con = -1 ;
    for ( int i=0 ; i < n ; i ++ )
    {
        con += ( parent[i] < 0 ) ;
    }

    int z = ed.size() ;

    if ( opt_d > z ) bad() ;

    vb taken_edge ( z ) ;

    for ( int i=0 ; i < z && opt_d != 0 ; i ++ )
    {
        int a = ed[i].F ;
        int b = ed[i].S ;

        bool ver = join ( a , b ) ;

        if ( ver )
        {
            con -- ;
            opt_d -- ;

            taken_edge[i] = 1 ;

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

            join ( a , b ) ;
        }
    }

    if ( con != 0 ) bad() ;

    for ( int i=0 ; i < z && opt_d != 0 ; i ++ )
    {
        if ( taken_edge[i] ) C ;

        int a = ed[i].F ;
        int b = ed[i].S ;

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

        opt_d -- ;
    }

    bfs ( 0 ) ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

const int N = 2e5 + 10 ;

int n , m , opt_d ;
vpii ed ;

int deg[N] ;

vi parent ( N , -1 ) ;

void read()
{
    cin >> n >> m >> opt_d ;

    ed.resize ( m ) ;
    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ; b -- ;

        deg[a] ++ ;
        deg[b] ++ ;

        ed[i] = { a , b } ;
    }
}

vpii ans_ed ;
int z = 0 ;
bool ok = false ;

int find_parent ( int indx )
{
    if ( parent[indx] < 0 )
        return indx ;

    return parent[indx] = find_parent ( parent[indx] ) ;
}

void join ( int a , int b )
{
    int p1 = find_parent ( a ) ;
    int p2 = find_parent ( b ) ;

    if ( p1 == p2 )
        return ;

    ans_ed.pb ( { a , b } ) ;
    z ++ ;

    if ( z == n - 1 ) /// This improves the Worst case performance of any Spanning tree algo. We may stop as soon as we have found n-1 edges
    {
        ok = true ;
        return ;
    }

    if ( parent[p1] > parent[p2] )
        swap ( p1 , p2 ) ;

    parent[p1] += parent[p2] ;
    parent[p2] = p1 ;
}

void join_all_edges_with_node_1()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 )
        {
            join ( a , b ) ;
            deg[0] -- ;

            if ( ok ) return ;
            if ( deg[0] == 0 ) return ;
        }
    }
}

void join_all_other_edges()
{
    for ( auto i : ed )
    {
        int a = i.F ;
        int b = i.S ;

        if ( a == 0 || b == 0 ) C ;

        join ( a , b ) ;
        if ( ok ) return ;
    }
}

void solve ( int test_case )
{
    read() ;

    if ( deg[0] < opt_d ) { cout << "NO" ; line ; return ; }

    deg[0] = opt_d ;
    join_all_edges_with_node_1() ;

    if ( ok == false )
        join_all_other_edges() ;

    cerr << "\nmy ans : \n" ;
    for ( auto i : ans_ed )
        cout << i.F + 1 << " " << i.S + 1 , line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    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<=d){
		    count=d;
		   // cout<<count<<"\n";
			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 id[maxn], v = 0, vis[maxn];
set<int> trees[maxn],gg[maxn];

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 breakit(int st,int& count){
	vis[st] = 1;
//	cout<<"yaaaaaaaaaaaaa\n";
	if (count == 0) return;
	for (int u : trees[st]){
		if (vis[u] == 0){
			if (count == 0) return;
//			cout<<u<<" "<<st<<nl;
			gg[u].erase(st);
			gg[st].erase(u);
			gg[1].ins(u);gg[1].ins(st);
			gg[u].ins(1);gg[st].ins(1);
			count--;
			breakit(u,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++;
	}
	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 - 1;
	if (v < d){
		initarr(vis,0);
		REP(i,2,n){
			if (count > 0 and vis[i] == 0) breakit(i,count);
			else break;
		}
	}
	else{
		for (int i : ha) {
			gg[1].ins(i);
			gg[i].ins(1);
		}
	}
	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<<"\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);
			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 id[maxn], v = 0, vis[maxn];
set<int> trees[maxn],gg[maxn];

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 breakit(int st,int& count){
	vis[st] = 1;
//	cout<<"yaaaaaaaaaaaaa\n";
	if (count == 0) return;
	for (int u : trees[st]){
		if (vis[u] == 0){
			if (count == 0) return;
//			cout<<u<<" "<<st<<nl;
			gg[u].erase(st);
			gg[st].erase(u);
			count--;
			breakit(u,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;
	set<int> avn;
	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 - 1;
	if (v < d){
		initarr(vis,0);
		for (int i : avn){
			if (count > 0 and vis[i] == 0) {
				breakit(i,count);
				gg[1].ins(i);
				gg[i].ins(1);
			}
			else break;
		}
	}
	else{
		for (int i : avn) {
			gg[1].ins(i);
			gg[i].ins(1);
		}
	}
	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,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;
	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(node);
	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 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);
		}
		if (count == 0) break;
	}
	initarr(vis,0);
	cout<<"YES\n";
	dfs1(1);
	return 0;
}