#include <stdio.h>
#include <stdlib.h>

int dance[ 100000 ][ 3 ];
int color[ 100000 ];
int n, m;

void dfs( int );

int main( void ) {
    int i;

    scanf( "%d %d", &n, &m );

    for ( i = 0; i < m; i++ )
        scanf( "%d %d %d", dance[ i ], dance[ i ] + 1, dance[ i ] + 2 );

    dfs( 0 );

    return 0;
}

void dfs( int i ) {
    int n1, n2, n3;

    if ( i == m ) {
        for ( i = 0; i < n; i++ )
            printf( "%d%c", color[ i ], i == n - 1 ? '\n' : ' ' );
        exit( 0 );
    }

    n1 = dance[ i ][ 0 ] - 1;
    n2 = dance[ i ][ 1 ] - 1;
    n3 = dance[ i ][ 2 ] - 1;

    if ( color[ n1 ] ) {
        switch ( color[ n1 ] ) {
        case 1:
            color[ n2 ] = 2;
            color[ n3 ] = 3;
            dfs( i + 1 );

            color[ n2 ] = 3;
            color[ n3 ] = 2;
            dfs( i + 1 );

            break;
        case 2:
            color[ n2 ] = 1;
            color[ n3 ] = 3;
            dfs( i + 1 );

            color[ n2 ] = 3;
            color[ n3 ] = 1;
            dfs( i + 1 );

            break;
        case 3:
            color[ n2 ] = 1;
            color[ n3 ] = 2;
            dfs( i + 1 );

            color[ n2 ] = 2;
            color[ n3 ] = 1;
            dfs( i + 1 );

            break;
        }

        color[ n2 ] = 0;
        color[ n3 ] = 0;
    } else if ( color[ n2 ] ) {
        switch ( color[ n2 ] ) {
        case 1:
            color[ n1 ] = 2;
            color[ n3 ] = 3;
            dfs( i + 1 );

            color[ n1 ] = 3;
            color[ n3 ] = 2;
            dfs( i + 1 );

            break;
        case 2:
            color[ n1 ] = 1;
            color[ n3 ] = 3;
            dfs( i + 1 );

            color[ n1 ] = 3;
            color[ n3 ] = 1;
            dfs( i + 1 );

            break;
        case 3:
            color[ n1 ] = 1;
            color[ n3 ] = 2;
            dfs( i + 1 );

            color[ n1 ] = 2;
            color[ n3 ] = 1;
            dfs( i + 1 );

            break;
        }

        color[ n1 ] = 0;
        color[ n3 ] = 0;
    } else if ( color[ n3 ] ) {
        switch ( color[ n3 ] ) {
        case 1:
            color[ n1 ] = 2;
            color[ n2 ] = 3;
            dfs( i + 1 );

            color[ n1 ] = 3;
            color[ n2 ] = 2;
            dfs( i + 1 );

            break;
        case 2:
            color[ n1 ] = 1;
            color[ n2 ] = 3;
            dfs( i + 1 );

            color[ n1 ] = 3;
            color[ n2 ] = 1;
            dfs( i + 1 );

            break;
        case 3:
            color[ n1 ] = 1;
            color[ n2 ] = 2;
            dfs( i + 1 );

            color[ n1 ] = 2;
            color[ n2 ] = 1;
            dfs( i + 1 );

            break;
        }

        color[ n1 ] = 0;
        color[ n2 ] = 0;
    } else {
        color[ n1 ] = 1;
        color[ n2 ] = 2;
        color[ n3 ] = 3;
        dfs( i + 1 );

        color[ n1 ] = 1;
        color[ n2 ] = 3;
        color[ n3 ] = 2;
        dfs( i + 1 );

        color[ n1 ] = 2;
        color[ n2 ] = 1;
        color[ n3 ] = 3;
        dfs( i + 1 );

        color[ n1 ] = 2;
        color[ n2 ] = 3;
        color[ n3 ] = 1;
        dfs( i + 1 );

        color[ n1 ] = 3;
        color[ n2 ] = 1;
        color[ n3 ] = 2;
        dfs( i + 1 );

        color[ n1 ] = 3;
        color[ n2 ] = 2;
        color[ n3 ] = 1;
        dfs( i + 1 );

        color[ n1 ] = 0;
        color[ n2 ] = 0;
        color[ n3 ] = 0;
    }

    return;
}


#include <stdio.h>

int dance[ 100000 ][ 3 ];
int color[ 100000 ];

void dfs( int );

int main( void ) {
    int i, n, m;
    scanf( "%d %d", &n, &m );

    for ( i = 0; i < m; i++ )
        scanf( "%d %d %d", dance[ i ], dance[ i ] + 1, dance[ i ] + 2 );

    for ( i = 0; i < m; i++ ) {
        int n1 = dance[ i ][ 0 ] - 1, n2 = dance[ i ][ 1 ] - 1, n3 = dance[ i ][ 2 ] - 1;

        if ( color[ n1 ] )
            switch ( color[ n1 ] ) {
            case 1:
                color[ n2 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n2 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n2 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n2 ] )
            switch ( color[ n2 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n3 ] )
            switch ( color[ n3 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n2 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n2 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n2 ] = 2;
                break;
            }
        else {
            color[ n1 ] = 1;
            color[ n2 ] = 2;
            color[ n3 ] = 3;
        }
    }

    for ( i = 0; i < n; i++ )
        printf( "%d%c", color[ i ], i == n - 1 ? '\n' : ' ' );

    return 0;
}


#include <stdio.h>

int a[200001];

int nextInt() {
    char ch;
    int sign, x;

    do {
        ch = getchar();
    } while (ch < '-');

    if (ch == '-') {
        sign = -1;
        ch = getchar();
    } else
        sign = 1;

    x = 0;
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }

    return sign * x;
}

void printInt(int x) {
    char ch[10];
    int sign, cnt;

    if (x < 0) {
        putchar('-');
        sign = -1;
    } else
        sign = 1;

    cnt = 0;
    do {
        ch[cnt++] = '0' + x % 10 * sign;
        x /= 10;
    } while (x);

    while (cnt--)
        putchar(ch[cnt]);
}

int color[100001];

int main(void) {
    int i, j;
    int n, m;

    n = nextInt();
    m = nextInt();

    while (m--) {
        int n[] = {nextInt(), nextInt(), nextInt()};
        for (i = 0; i < 3 && !color[n[i]]; i++) ;
        if (i == 3)
            for (j = 0; j < 3; j++)
                color[n[j]] = j + 1;
        else {
            color[n[(i + 1) % 3]] = color[n[i]] % 3 + 1;
            color[n[(i + 2) % 3]] = (color[n[i]] + 1) % 3 + 1;
        }
    }

    for (i = 1; i <= n; i++) {
        printInt(color[i]);
        putchar(' ');
    }
    putchar('\n');

    return 0;
}


#include <stdio.h>

int a[200001];

int nextInt() {
    char ch;
    int sign, x;

    do {
        ch = getchar();
    } while (ch < '-');

    if (ch == '-') {
        sign = -1;
        ch = getchar();
    } else
        sign = 1;

    x = 0;
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }

    return sign * x;
}

void printInt(int x) {
    char ch[10];
    int sign, cnt;

    if (x < 0) {
        putchar('-');
        sign = -1;
    } else
        sign = 1;

    cnt = 0;
    do {
        ch[cnt++] = '0' + x % 10 * sign;
        x /= 10;
    } while (x);

    while (cnt--)
        putchar(ch[cnt]);
}

int color[100001];

int main(void) {
    int i;
    int n, m;

    n = nextInt();
    m = nextInt();

    while (m--) {
        int n1 = nextInt(), n2 = nextInt(), n3 = nextInt();
        if (color[n1]) {
            color[n2] = color[n1] % 3 + 1;
            color[n3] = (color[n1] + 1) % 3 + 1;
        } else if (color[n2]) {
            color[n3] = color[n2] % 3 + 1;
            color[n1] = (color[n2] + 1) % 3 + 1;
        } else if (color[n3]) {
            color[n1] = color[n3] % 3 + 1;
            color[n2] = (color[n3] + 1) % 3 + 1;
        } else {
            color[n1] = 1;
            color[n2] = 2;
            color[n3] = 3;
        }
    }

    for (i = 1; i <= n; i++) {
        printInt(color[i]);
        putchar(' ');
    }
    putchar('\n');

    return 0;
}


#include <stdio.h>

int color[ 100001 ];

void dfs( int );

int main( void ) {
    int i, n, m, n1, n2, n3;

    scanf( "%d %d", &n, &m );

    for ( i = 0; i < m; i++ ) {
        scanf( "%d %d %d", &n1, &n2, &n3 );

        if ( color[ n1 ] )
            switch ( color[ n1 ] ) {
            case 1:
                color[ n2 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n2 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n2 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n2 ] )
            switch ( color[ n2 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n3 ] )
            switch ( color[ n3 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n2 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n2 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n2 ] = 2;
                break;
            }
        else {
            color[ n1 ] = 1;
            color[ n2 ] = 2;
            color[ n3 ] = 3;
        }
    }

    for ( i = 1; i <= n; i++ )
        printf( "%d%c", color[ i ], i == n ? '\n' : ' ' );

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int dance[ 100000 ][ 3 ];
int color[ 100000 ];
int n, m;

void dfs( int );

int main( void ) {
    int i;

    scanf( "%d %d", &n, &m );

    for ( i = 0; i < m; i++ )
        scanf( "%d %d %d", dance[ i ], dance[ i ] + 1, dance[ i ] + 2 );

    for ( i = 0; i < m; i++ ) {
        int n1 = dance[ i ][ 0 ] - 1, n2 = dance[ i ][ 1 ] - 1, n3 = dance[ i ][ 2 ] - 1;

        if ( color[ n1 ] )
            switch ( color[ n1 ] ) {
            case 1:
                color[ n2 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n2 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n2 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n2 ] )
            switch ( color[ n2 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n3 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n3 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n3 ] = 2;
                break;
            }
        else if ( color[ n3 ] )
            switch ( color[ n3 ] ) {
            case 1:
                color[ n1 ] = 2;
                color[ n2 ] = 3;
                break;
            case 2:
                color[ n1 ] = 1;
                color[ n2 ] = 3;
                break;
            case 3:
                color[ n1 ] = 1;
                color[ n2 ] = 2;
                break;
            }
        else {
            color[ n1 ] = 1;
            color[ n2 ] = 2;
            color[ n3 ] = 3;
        }
    }

    for ( i = 0; i < n; i++ )
        printf( "%d%c", color[ i ], i == n - 1 ? '\n' : ' ' );

    return 0;
}


#include <stdio.h>

int nextInt() {
    char ch;
    int sign, x;

    do {
        ch = getchar();
    } while (ch < '-');

    if (ch == '-') {
        sign = -1;
        ch = getchar();
    } else
        sign = 1;

    x = 0;
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }

    return sign * x;
}

void printInt(int x) {
    char ch[10];
    int sign, cnt;

    if (x < 0) {
        putchar('-');
        sign = -1;
    } else
        sign = 1;

    cnt = 0;
    do {
        ch[cnt++] = '0' + x % 10 * sign;
        x /= 10;
    } while (x);

    while (cnt--)
        putchar(ch[cnt]);
}

int color[100001];

int main(void) {
    int i, j;
    int n, m;

    n = nextInt();
    m = nextInt();

    while (m--) {
        int n[] = {nextInt(), nextInt(), nextInt()};
        for (i = 0; i < 3 && !color[n[i]]; i++) ;
        if (i == 3)
            for (j = 0; j < 3; j++)
                color[n[j]] = j + 1;
        else {
            color[n[(i + 1) % 3]] = color[n[i]] % 3 + 1;
            color[n[(i + 2) % 3]] = (color[n[i]] + 1) % 3 + 1;
        }
    }

    for (i = 1; i <= n; i++) {
        printInt(color[i]);
        putchar(' ');
    }
    putchar('\n');

    return 0;
}


#include"stdio.h"
#include"string.h"

int x[100005],y[100005],z[100005];
int flag[100005]={0};

int main( )
{
	int n,m;
	int i,j,sign[5];
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	{
		memset(sign,0,sizeof(sign));
		scanf("%d%d%d",&x[i],&y[i],&z[i]);
		sign[flag[x[i]]] = 1;
		sign[flag[y[i]]] = 1;
		sign[flag[z[i]]] = 1;
		for(j=1;j<4;j++)
		{
			if(sign[j]==1)
			  continue;
			if(flag[x[i]]==0)
				flag[x[i]] = j;
			else if(flag[y[i]]==0)
				flag[y[i]] = j;
			else if(flag[z[i]]==0)
				flag[z[i]] = j;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(i!=1)
		  printf(" ");
		printf("%d",flag[i]);
	}
	printf("\n");
	return 0;
}


#include <stdio.h>
struct str_dance
{
       int p1;
       int p2;
       int p3;
};
struct str_dance dance[100000];
int color[100000],n,m;

void dfs(int num)
{
     if (num==m+1)
     {
        int i,h,k;
        for (h=1;h<=n;h++)
            if (color[h]==0)
               printf("1");
            else
                printf("%d ",color[h]);
        //system("pause");
        exit(0);
     }
     if (color[dance[num].p1]!=0&&color[dance[num].p2]==0&&color[dance[num].p3]==0)
     {
        if (color[dance[num].p1]==1)
        {
           color[dance[num].p2]=2;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p2]=3;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p1]==2)
        {
           color[dance[num].p2]=1;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p2]=3;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p1]==3)
        {
           color[dance[num].p2]=2;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p2]=1;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
     }
     else if (color[dance[num].p2]!=0&&color[dance[num].p1]==0&&dance[num].p3==0)
     {
        if (color[dance[num].p2]==1)
        {
           color[dance[num].p1]=2;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p2]==2)
        {
           color[dance[num].p1]=1;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p2]==3)
        {
           color[dance[num].p1]=2;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p1]=1;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
     }
     else if (color[dance[num].p3]!=0&&color[dance[num].p1]==0&&color[dance[num].p2]==0)
     {
        if (color[dance[num].p3]==1)
        {
           color[dance[num].p1]=2;
           color[dance[num].p2]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p2]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
        else if (color[dance[num].p3]==2)
        {
           color[dance[num].p1]=1;
           color[dance[num].p2]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p2]=1;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
        else if (color[dance[num].p3]==3)
        {
           color[dance[num].p1]=2;
           color[dance[num].p2]=1;
           dfs(num+1);
           color[dance[num].p1]=1;
           color[dance[num].p2]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p2]!=0&&color[dance[num].p3]==0)
     {
          if (color[dance[num].p1]!=color[dance[num].p2])
          {
             color[dance[num].p3]=6-color[dance[num].p1]-color[dance[num].p2];
             dfs(num+1);
             color[dance[num].p3]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p2]!=0&&color[dance[num].p3]!=0&&color[dance[num].p1]==0)
     {
          if (color[dance[num].p3]!=color[dance[num].p2])
          {
             color[dance[num].p1]=6-color[dance[num].p3]-color[dance[num].p2];
             dfs(num+1);
             color[dance[num].p1]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p3]!=0&&color[dance[num].p2]==0)
     {
          if (color[dance[num].p1]!=color[dance[num].p3])
          {
             color[dance[num].p2]=6-color[dance[num].p1]-color[dance[num].p3];
             dfs(num+1);
             color[dance[num].p2]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p2]!=0&&color[dance[num].p3]!=0)
     {
          if (color[dance[num].p1]+color[dance[num].p2]+color[dance[num].p3]==6&&color[dance[num].p1]!=color[dance[num].p2])
             dfs(num+1);
          else
              return;
     }
     else if (color[dance[num].p1]==0&&color[dance[num].p2]==0&&color[dance[num].p3]==0)
     {
          color[dance[num].p1]=1;
          color[dance[num].p2]=2;
          color[dance[num].p3]=3;
          dfs(num+1);
          color[dance[num].p1]=1;
          color[dance[num].p2]=3;
          color[dance[num].p3]=2;
          dfs(num+1);
          color[dance[num].p1]=2;
          color[dance[num].p2]=3;
          color[dance[num].p3]=1;
          dfs(num+1);
          color[dance[num].p1]=2;
          color[dance[num].p2]=1;
          color[dance[num].p3]=3;
          dfs(num+1);
          color[dance[num].p1]=3;
          color[dance[num].p2]=1;
          color[dance[num].p3]=2;
          dfs(num+1);
          color[dance[num].p1]=3;
          color[dance[num].p2]=2;
          color[dance[num].p3]=1;
          dfs(num+1);
          color[dance[num].p1]=0;
          color[dance[num].p2]=0;
          color[dance[num].p3]=0;
     }
     return;
}

int main()
{
    int i;
    memset(color,0,sizeof(color));
    scanf("%d %d",&n,&m);
    for (i=1;i<=m;i++)
        scanf("%d %d %d",&dance[i].p1,&dance[i].p2,&dance[i].p3);
    dfs(1);
    //system("pause");
    return 0;
}


#include <stdio.h>
struct str_dance
{
       int p1;
       int p2;
       int p3;
};
struct str_dance dance[200000];
int color[200000],n,m;

void dfs(int num)
{
     if (num==m+1)
     {
        int i,h,k;
        for (h=1;h<=n;h++)
            if (color[h]==0)
               printf("1");
            else
                printf("%d ",color[h]);
        //system("pause");
        exit(0);
     }
     if (color[dance[num].p1]!=0&&color[dance[num].p2]==0&&color[dance[num].p3]==0)
     {
        if (color[dance[num].p1]==1)
        {
           color[dance[num].p2]=2;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p2]=3;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p1]==2)
        {
           color[dance[num].p2]=1;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p2]=3;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p1]==3)
        {
           color[dance[num].p2]=2;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p2]=1;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p2]=0;
           color[dance[num].p3]=0;
        }
     }
     else if (color[dance[num].p2]!=0&&color[dance[num].p1]==0&&color[dance[num].p3]==0)
     {
        if (color[dance[num].p2]==1)
        {
           color[dance[num].p1]=2;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p2]==2)
        {
           color[dance[num].p1]=1;
           color[dance[num].p3]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
        else if (color[dance[num].p2]==3)
        {
           color[dance[num].p1]=2;
           color[dance[num].p3]=1;
           dfs(num+1);
           color[dance[num].p1]=1;
           color[dance[num].p3]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p3]=0;
        }
     }
     else if (color[dance[num].p3]!=0&&color[dance[num].p1]==0&&color[dance[num].p2]==0)
     {
        if (color[dance[num].p3]==1)
        {
           color[dance[num].p1]=2;
           color[dance[num].p2]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p2]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
        else if (color[dance[num].p3]==2)
        {
           color[dance[num].p1]=1;
           color[dance[num].p2]=3;
           dfs(num+1);
           color[dance[num].p1]=3;
           color[dance[num].p2]=1;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
        else if (color[dance[num].p3]==3)
        {
           color[dance[num].p1]=2;
           color[dance[num].p2]=1;
           dfs(num+1);
           color[dance[num].p1]=1;
           color[dance[num].p2]=2;
           dfs(num+1);
           color[dance[num].p1]=0;
           color[dance[num].p2]=0;
        }
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p2]!=0&&color[dance[num].p3]==0)
     {
          if (color[dance[num].p1]!=color[dance[num].p2])
          {
             color[dance[num].p3]=6-color[dance[num].p1]-color[dance[num].p2];
             dfs(num+1);
             color[dance[num].p3]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p2]!=0&&color[dance[num].p3]!=0&&color[dance[num].p1]==0)
     {
          if (color[dance[num].p3]!=color[dance[num].p2])
          {
             color[dance[num].p1]=6-color[dance[num].p3]-color[dance[num].p2];
             dfs(num+1);
             color[dance[num].p1]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p3]!=0&&color[dance[num].p2]==0)
     {
          if (color[dance[num].p1]!=color[dance[num].p3])
          {
             color[dance[num].p2]=6-color[dance[num].p1]-color[dance[num].p3];
             dfs(num+1);
             color[dance[num].p2]=0;
          }
          else
              return;
     }
     else if (color[dance[num].p1]!=0&&color[dance[num].p2]!=0&&color[dance[num].p3]!=0)
     {
          if (color[dance[num].p1]+color[dance[num].p2]+color[dance[num].p3]==6&&color[dance[num].p1]!=color[dance[num].p2])
             dfs(num+1);
          else
              return;
     }
     else if (color[dance[num].p1]==0&&color[dance[num].p2]==0&&color[dance[num].p3]==0)
     {
          color[dance[num].p1]=1;
          color[dance[num].p2]=2;
          color[dance[num].p3]=3;
          dfs(num+1);
          color[dance[num].p1]=1;
          color[dance[num].p2]=3;
          color[dance[num].p3]=2;
          dfs(num+1);
          color[dance[num].p1]=2;
          color[dance[num].p2]=3;
          color[dance[num].p3]=1;
          dfs(num+1);
          color[dance[num].p1]=2;
          color[dance[num].p2]=1;
          color[dance[num].p3]=3;
          dfs(num+1);
          color[dance[num].p1]=3;
          color[dance[num].p2]=1;
          color[dance[num].p3]=2;
          dfs(num+1);
          color[dance[num].p1]=3;
          color[dance[num].p2]=2;
          color[dance[num].p3]=1;
          dfs(num+1);
          color[dance[num].p1]=0;
          color[dance[num].p2]=0;
          color[dance[num].p3]=0;
     }
     return;
}

int main()
{
    int i;
    memset(color,0,sizeof(color));
    scanf("%d %d",&n,&m);
    for (i=1;i<=m;i++)
        scanf("%d %d %d",&dance[i].p1,&dance[i].p2,&dance[i].p3);
    dfs(1);
    //system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc, char const *argv[])
{
	int n,m,i,j,temp1,temp2,temp3;
	scanf("%d %d",&n,&m);
	int a[n+1],c[n+1],flag=0;
	//int b[m+1][3];
	for(i=0;i<n+1;i=i+1){
		a[i]=0;
		c[i]=0;
	}
	for(i=1;i<=m;i=i+1){
		scanf("%d %d %d",&temp1,&temp2,&temp3);
		if(c[temp1]==0&&c[temp2]==0&&c[temp3]==0){
		    c[temp1]=1;
		    c[temp2]=2;
		    c[temp3]=3;
		}else if(c[temp1]!=0){
			if(c[temp1]==1){
				c[temp2]=2;
				c[temp3]=3;
			}else if(c[temp1]==2){
				c[temp2]=1;
				c[temp3]=3;
			}else if(c[temp1]==3){
				c[temp2]=1;
				c[temp3]=2;
			}
		}else if(c[temp2]!=0){
			if(c[temp2]==1){
				c[temp1]=2;
				c[temp3]=3;
			}else if(c[temp2]==2){
				c[temp1]=1;
				c[temp3]=3;
			}else if(c[temp2]==3){
				c[temp1]=1;
				c[temp3]=2;
			}
		}else if(c[temp3]!=0){
			if(c[temp3]==1){
				c[temp1]=2;
				c[temp2]=3;
			}else if(c[temp3]==2){
				c[temp1]=1;
				c[temp2]=3;
			}else if(c[temp3]==3){
				c[temp1]=1;
				c[temp2]=2;
			}
		}
	}
	for(i=1;i<=n;i=i+1){
		printf("%d ",c[i]);
	}
	return 0;
}


#include <stdio.h>
int main()
{
	long n,m,i,x,y,z;
	int color[100005];
	scanf("%ld%ld",&n,&m);
	for(i=1;i<=n;i++) color[i]=0;
	for(i=1;i<=m;i++){
		scanf("%ld%ld%ld",&x,&y,&z);
		if(color[x]!=0) {color[y]=color[x]%3+1;color[z]=color[y]%3+1;}
		else
		if(color[y]!=0) {color[z]=color[y]%3+1;color[x]=color[z]%3+1;}
		else
		if(color[z]!=0) {color[x]=color[z]%3+1;color[y]=color[x]%3+1;}
		else{ color[x]=1;color[y]=2;color[z]=3;};
	}
	for(i=1;i<=n;i++) printf("%d ",color[i]);
	printf("\n");
	return 0;
}


#include<stdio.h>
int hash[100015];

int main()
{
    int m,a,b,c,n,i,temp;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        if(hash[a] != 0)
        {
            if(hash[a] == 1)
            {
                hash[b] = 2;
                hash[c] = 3;
            }
            else if(hash[a] == 2)
            {
                hash[b] = 1;
                hash[c] = 3;
            }
            else if(hash[a] == 3)
            {
                hash[b] = 1;
                hash[c] = 2;
            }
        }
        else if(hash[b] != 0)
        {
            if(hash[b] == 1)
            {
                hash[a] = 2;
                hash[c] = 3;
            }
            else if(hash[b] == 2)
            {
                hash[a] = 1;
                hash[c] = 3;
            }
            else if(hash[b] == 3)
            {
                hash[a] = 1;
                hash[c] = 2;
            }
        }
        else if(hash[c] != 0)
        {
            if(hash[c] == 1)
            {
                hash[a] = 2;
                hash[b] = 3;
            }
            else if(hash[c] == 2)
            {
                hash[a] = 1;
                hash[b] = 3;
            }
            else if(hash[c] == 3)
            {
                hash[a] = 1;
                hash[b] = 2;
            }
        }
        else
        {
            hash[a] = 1;
            hash[b] = 2;
            hash[c] = 3;
        }
    }
    for(i=1;i<=n;i++)
        printf("%d ",hash[i]);
    printf("\n");
    return 0;
}


#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

char data[100001];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    fore (i, 1, m) {
        int a, b, c, pd, po1, po2;
        scanf("%d %d %d", &a, &b, &c);
        if (data[a] != 0) {
            pd = a;
            po1 = b;
            po2 = c;
        } else if (data[b] != 0) {
            pd = b;
            po1 = a;
            po2 = c;
        } else if (data[c] != 0) {
            pd = c;
            po1 = a;
            po2 = b;
        } else {
            pd = a;
            po1 = b;
            po2 = c;
            data[pd] = 1;
        }
        if (data[pd] == 1) {
            data[po1] = 2;
            data[po2] = 3;
        } else if (data[pd] == 2) {
            data[po1] = 1;
            data[po2] = 3;
        } else {
            data[po1] = 1;
            data[po2] = 2;
        }
    }
    fore (i, 1, n) {
        printf("%d ", data[i]);
    }
    putchar('\n');
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{

	int n, m, i;
	int color[100001];

	scanf("%d%d",&n,&m);
	memset(color, -1, sizeof(color));
	for (i = 0; i < m; i++)
	{
		int a, b, c;

		scanf("%d%d%d",&a,&b,&c);
		if (color[a] == -1 && color[b] == -1 && color[c] == -1)
		{
			color[a] = 0, color[b] = 1, color[c] = 2;
		}
		else if(color[a] != -1)
		{
			color[b] = (color[a] + 1 ) % 3;
			color[c] = (color[b] + 1 ) % 3;
		}
		else if(color[b] != -1)
		{
			color[a] = (color[b] + 1 ) % 3;
			color[c] = (color[a] + 1 ) % 3;
		}
		else
		{
			color[a] = (color[c] + 1 ) % 3;
			color[b] = (color[a] + 1 ) % 3;
		}
	}
	for (i = 1; i <= n; i++)
	{
		printf("%d ", color[i]+1);
	}
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{

	int n, m, i;
	int color[100001];

	scanf("%d%d",&n,&m);
	memset(color, -1, sizeof(color));
	for (i = 0; i < m; i++)
	{
		int a, b, c;

		scanf("%d%d%d",&a,&b,&c);
		if (color[a] == -1 && color[b] == -1 && color[c] == -1)
		{
			color[a] = 0, color[b] = 1, color[c] = 2;
		}
		else if(color[a] != -1)
		{
			color[b] = (color[a] + 1 ) % 3;
			color[c] = (color[b] + 1 ) % 3;
		}
		else if(color[b] != -1)
		{
			color[a] = (color[b] + 1 ) % 3;
			color[c] = (color[a] + 1 ) % 3;
		}
		else if(color[c] != -1)
		{
			color[a] = (color[c] + 1 ) % 3;
			color[b] = (color[a] + 1 ) % 3;
		}
	}
	for (i = 1; i <= n; i++)
	{
		printf("%d ", color[i]+1);
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
	int i,j,k,n,m,here,now[3],color[100010];
	scanf("%d%d",&n,&m);
	memset(color,0,sizeof(color));
	while(m--)
	{
		scanf("%d%d%d",&now[0],&now[1],&now[2]);
		here=-1;
		for(i=0;i<3;i++)
		{
			if(color[now[i]]>0)
			{
				here=color[now[i]];
				break;
			}
		}
		k=1;
		for(j=0;j<3;j++)
		{
			if(k==here)
				k++;
			if(j==i)
				continue;
			color[now[j]]=k++;
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ",color[i]);
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{  long  n,m;
scanf("%ld %ld",&n,&m);
long i,arr[3],list[n];

for(i=0;i<n;i++)
list[i]=0;

int flag1,flag2;

while(m--)
{flag1=-1;
    for(i=0;i<3;i++)
    {
    scanf("%ld",&arr[i]);
    if(list[arr[i]-1]==0)
    list[arr[i]-1]=i+1;

    else
    {flag1=i;
    flag2=list[arr[i]-1];
    }

   }
    if(flag1>=0)
   list[arr[flag2-1]-1]=flag1+1;
}
for(i=0;i<n;i++)
printf("%ld ",list[i]);
return 0;
}


#include <stdio.h>
#include <string.h>

int color[100005];

void func(int a, int b, int c){
	int vis[4];
	memset(vis, 0, sizeof(vis));
	if(color[a]){
		vis[color[a]] = 1;
	}
	if(color[b]){
		vis[color[b]] = 1;
	}
	if(color[c]){
		vis[color[c]] = 1;
	}
	int i;
	for (i = 1; i <= 3; i++){
		if (!vis[i]){
			if (!color[a]){
				color[a] = i;
			}
			else if (!color[b]){
				color[b] = i;
			}
			else if (!color[c]){
				color[c] = i;
			}
		}
	}
}

int main(void){
	int n, m;
	while (~scanf("%d %d", &n, &m)) {
		int i;
		memset(color, 0, sizeof(color));
		for (i = 0; i < m; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			func(a, b, c);
		}
		for (i = 1; i <= n; i++){
			printf("%d%c", color[i], i==n ? '\n' : ' ');
		}
	}
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int Color[100000] = {0};
void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

	int i, a, b, c;

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(Color[a-1]!=0)
		{
			Color[b-1] =Color[a-1] + 1;
			Color[c-1] =Color[a-1] + 2;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
			if(Color[c-1] >3)
				Color[c-1] -= 3;
		}
		else if(Color[b-1] != 0)
		{
			Color[a-1] = Color[b-1] + 2;
			Color[c-1] = Color[b-1] + 1;
			if(Color[a-1] > 3)
			{
				Color[a-1] -= 3;
			}
			if(Color[b-1] > 3)
				Color[c-1] -= 3;
		}
		else if(Color[c-1] != 0)
		{
			Color[a-1] = Color[c-1] + 1;
			Color[b-1] = Color[c-1] + 2;
			if(Color[a-1] > 3)
				Color[a-1] -= 3;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
		}
		else
		{
			Color[a-1] = 1;
			Color[b-1] = 2;
			Color[c-1] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		printf("%d ",Color[i]);
	}

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, m;
	scanf("%d %d",&n,&m);

   	int *Color;
	Color = (int *)malloc((m*3)*sizeof(int));

	int i, a, b, c;

	for(i=0;i<m*3;i++)
	{
		Color[i] = 0;
	}
	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		a -= 1;
		b -= 1;
		c -= 1;
		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 1;
			Color[c] =Color[a] + 2;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[c] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		if(i==0)
		printf("%d",Color[i]);
		else
		printf(" %d",Color[i]);
	}
	return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int Color[100000] = {0};
void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

	int i, a, b, c;

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(Color[a-1]!=0)
		{
			Color[b-1] =Color[a-1] + 2;
			Color[c-1] =Color[a-1] + 1;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
			if(Color[c-1] >3)
				Color[c-1] -= 3;
		}
		else if(Color[b-1] != 0)
		{
			Color[a-1] = Color[b-1] + 2;
			Color[c-1] = Color[b-1] + 1;
			if(Color[a-1] > 3)
			{
				Color[a-1] -= 3;
			}
			if(Color[b-1] > 3)
				Color[c-1] -= 3;
		}
		else if(Color[c-1] != 0)
		{
			Color[a-1] = Color[c-1] + 1;
			Color[b-1] = Color[c-1] + 2;
			if(Color[a-1] > 3)
				Color[a-1] -= 3;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
		}
		else
		{
			Color[a-1] = 1;
			Color[b-1] = 2;
			Color[c-1] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		printf("%d ",Color[i]);
	}

}


#include<string.h>
#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int i;
    int a[n];
    memset(a, 0, sizeof(a));
    for(i=0;i<m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        x--,y--,z--;
        if(!(a[x]||a[y]||a[z]))
        {
            a[x]=1;a[y]=2;a[z]=3;
        }
        else
        {
            if(a[x])
            {
                switch (a[x])
                {
                    case 1: a[y]=2;a[z]=3;break;
                    case 2: a[y]=1;a[z]=3;break;
                    case 3: a[y]=2;a[z]=1;break;
                }
            }
            else if(a[y])
            {
                switch (a[y])
                {
                    case 1: a[x]=2;a[z]=3;break;
                    case 2: a[x]=1;a[z]=3;break;
                    case 3: a[x]=2;a[z]=1;break;
                }
            }
            else if(a[z])
            {
                switch (a[z])
                {
                    case 1: a[x]=2;a[y]=3;break;
                    case 2: a[x]=1;a[y]=3;break;
                    case 3: a[x]=2;a[y]=1;break;
                }
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if(!a[i]) a[i]=1;
        printf("%d ",a[i]);
    }
    return 0;
}


#include<stdio.h>
int flag[100001];
int main(){
	int n,m,i,p=1,a,b,c;
	scanf("%d %d", &n, &m);
	for(i=0;i<m;i++){
		scanf("%d %d %d", &a, &b, &c);
		if(flag[a]>0||flag[b]>0||flag[c]>0)
		{
			if(flag[a])
				p=flag[a];
			else if(flag[b])
				p=flag[b];
			else
				p=flag[c];
			p = (p%3)+1;
			if(flag[a]==0)
			{
				flag[a]=p;
				p=(p%3)+1;
			}
			if(flag[b]==0)
			{
				flag[b]=p;
				p=(p%3)+1;
			}
			if(flag[c]==0)
			{
				flag[c]=p;
				p=(p%3)+1;
			}
		}
		else
		{
			flag[a]=1;
			flag[b]=2;
			flag[c]=3;
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ", flag[i]);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, m;
	scanf("%d %d",&n,&m);

   	int *Color;
	Color = (int *)malloc((m*3)*sizeof(int));

	int i, a, b, c;

	for(i=0;i<m*3;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		a -= 1;
		b -= 1;
		c -= 1;
		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[c] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		if(i==0)
		printf("%d",Color[i]);
		else
		printf(" %d",Color[i]);
	}
	return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, m;
	scanf("%d %d",&n,&m);

   	int *Color;
	Color = (int *)malloc((m*m+10)*sizeof(int));

	int i, a, b, c;

	for(i=0;i<m*m;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);

		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[b] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=1;i<=n;i++)
	{
		if(i==1)
		printf("%d",Color[i]);
		else
		printf(" %d",Color[i]);
	}
	return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int Color[100000];
void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

	int i, a, b, c;

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(Color[a-1]!=0)
		{
			Color[b-1] =Color[a-1] + 2;
			Color[c-1] =Color[a-1] + 1;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
			if(Color[c-1] >3)
				Color[c-1] -= 3;
		}
		else if(Color[b-1] != 0)
		{
			Color[a-1] = Color[b-1] + 2;
			Color[c-1] = Color[b-1] + 1;
			if(Color[a-1] > 3)
			{
				Color[a-1] -= 3;
			}
			if(Color[b-1] > 3)
				Color[c-1] -= 3;
		}
		else if(Color[c-1] != 0)
		{
			Color[a-1] = Color[c-1] + 1;
			Color[b-1] = Color[c-1] + 2;
			if(Color[a-1] > 3)
				Color[a-1] -= 3;
			if(Color[b-1] > 3)
				Color[b-1] -= 3;
		}
		else
		{
			Color[a-1] = 1;
			Color[b-1] = 2;
			Color[c-1] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		printf("%d ",Color[i]);
	}

}


#include <stdio.h>
#include <stdlib.h>

void InitArray(int num1,int num2)
{
	int *Color;
	Color = (int *)malloc((num2*num2+10)*sizeof(int));

	int i, a, b, c;

	for(i=0;i<num1;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<num2;i++)
	{
		scanf("%d %d %d",&a,&b,&c);

		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[b] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=1;i<=num1;i++)
	{
		printf("%d ",Color[i]);
	}
}

void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

    InitArray(n,m);

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, m;
	scanf("%d %d",&n,&m);

   	int *Color;
	Color = (int *)malloc((m*3)*sizeof(int));

	int i, a, b, c;

	for(i=0;i<m*3;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		a -= 1;
		b -= 1;
		c -= 1;
		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[b] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=0;i<n;i++)
	{
		if(i==0)
		printf("%d",Color[i]);
		else
		printf(" %d",Color[i]);
	}
	return 0;

}


#include <stdio.h>
#include <stdlib.h>

void InitArray(int num1,int num2)
{
	int *Color;
	Color = (int *)malloc(num1*sizeof(int));

	int i, a, b, c;

	for(i=0;i<num1;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<num2;i++)
	{
		scanf("%d %d %d",&a,&b,&c);

		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[b] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=1;i<=num1;i++)
	{
		printf("%d ",Color[i]);
	}
}

void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

    InitArray(n,m);

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

void InitArray(int num1,int num2)
{
	int *Color;
	Color = (int *)malloc(num1*sizeof(int));

	int i, a, b, c;

	for(i=0;i<num1;i++)
	{
		Color[i] = 0;
	}

	for(i=0;i<num2;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		a -= 1;
		b -= 1;
		c -= 1;
		if(Color[a]!=0)
		{
			Color[b] =Color[a] + 2;
			Color[c] =Color[a] + 1;
			if(Color[b] > 3)
				Color[b] -= 3;
			if(Color[c] >3)
				Color[c] -= 3;
		}
		else if(Color[b] != 0)
		{
			Color[a] = Color[b] + 2;
			Color[c] = Color[b] + 1;
			if(Color[a] > 3)
			{
				Color[a] -= 3;
			}
			if(Color[b] > 3)
				Color[c] -= 3;
		}
		else if(Color[c] != 0)
		{
			Color[a] = Color[c] + 1;
			Color[b] = Color[c] + 2;
			if(Color[a] > 3)
				Color[a] -= 3;
			if(Color[b] > 3)
				Color[b] -= 3;
		}
		else
		{
			Color[a] = 1;
			Color[b] = 2;
			Color[c] = 3;
		}
	}

	for(i=0;i<num1;i++)
	{
		printf("%d ",Color[i]);
	}
}

void main()
{
	int n, m;
	scanf("%d %d",&n,&m);

    InitArray(n,m);

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define lld long long int
#define llu long long unsigned int
int compare(const void * a, const void * b){return *(lld *)a-*(lld *)b;}
//long long int readlint() {long long int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
//int readint() {int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
#define min(a,b)((a)>(b)?(b):(a))
#define max(a,b)((a)<(b)?(b):(a))
#define sort(arr,n) qsort(arr,n,sizeof(arr[0]),compare)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define su(n) scanf("%llu",&n)
#define ss(n) scanf("%s",n)
#define FOR(i,start,end) for(i=start; i<end; i++)
#define pdn(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pun(n) printf("%llu\n",n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define pu(n) printf("%llu",n)
#define pn puts("")
#define ps putchar_unlocked(' ')
void swap(int *x,int *y)
{
	*x=*x^*y;
	*y=*x^*y;
	*x=*x^*y;
}
int main()
{
	int i,j,k,n,t,m,a,b,c;
	sd(n);
	sd(m);
	int has[400000];
	for(i=0;i<=n;i++)
		has[i]=-1;
	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(has[a]!=-1)
		{
			has[b]=(has[a]+1)%3;
			has[c]=(has[a]+2)%3;
		}
		else if(has[b]!=-1)
		{
			has[a]=(has[a]+1)%3;
			has[c]=(has[a]+2)%3;
		}
		else if(has[c]!=-1)
		{
			has[b]=(has[a]+1)%3;
			has[a]=(has[a]+2)%3;
		}
		else
		{
			has[a]=0;
			has[b]=1;
			has[c]=2;
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ",has[i]+1);
	puts("");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define lld long long int
#define llu long long unsigned int
int compare(const void * a, const void * b){return *(lld *)a-*(lld *)b;}
//long long int readlint() {long long int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
//int readint() {int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
#define min(a,b)((a)>(b)?(b):(a))
#define max(a,b)((a)<(b)?(b):(a))
#define sort(arr,n) qsort(arr,n,sizeof(arr[0]),compare)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define su(n) scanf("%llu",&n)
#define ss(n) scanf("%s",n)
#define FOR(i,start,end) for(i=start; i<end; i++)
#define pdn(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pun(n) printf("%llu\n",n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define pu(n) printf("%llu",n)
#define pn puts("")
#define ps putchar_unlocked(' ')
void swap(int *x,int *y)
{
	*x=*x^*y;
	*y=*x^*y;
	*x=*x^*y;
}
int main()
{
	int i,j,k,n,t,m,a,b,c;
	sd(n);
	sd(m);
	int has[400000];
	for(i=0;i<=n+1;i++)
		has[i]=-1;
	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(has[a]!=-1)
		{
			has[b]=(has[a]+1)%3;
			has[c]=(has[a]+2)%3;
		}
		else if(has[b]!=-1)
		{
			has[a]=(has[b]+1)%3;
			has[c]=(has[b]+2)%3;
		}
		else if(has[c]!=-1)
		{
			has[b]=(has[c]+1)%3;
			has[a]=(has[c]+2)%3;
		}
		else
		{
			has[a]=0;
			has[b]=1;
			has[c]=2;
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ",has[i]+1);
	puts("");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define lld long long int
#define llu long long unsigned int
int compare(const void * a, const void * b){return *(lld *)a-*(lld *)b;}
//long long int readlint() {long long int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
//int readint() {int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
#define min(a,b)((a)>(b)?(b):(a))
#define max(a,b)((a)<(b)?(b):(a))
#define sort(arr,n) qsort(arr,n,sizeof(arr[0]),compare)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define su(n) scanf("%llu",&n)
#define ss(n) scanf("%s",n)
#define FOR(i,start,end) for(i=start; i<end; i++)
#define pdn(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pun(n) printf("%llu\n",n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define pu(n) printf("%llu",n)
#define pn puts("")
#define ps putchar_unlocked(' ')
void swap(int *x,int *y)
{
	*x=*x^*y;
	*y=*x^*y;
	*x=*x^*y;
}
int main()
{
	int i,j,k,n,t;
	sd(n);
	int a[20000]={0},l;
	for(i=0;i<n;i++)
	{
		scanf("%d",&l);
		a[i+1]=a[i]+l;
	}
	int x,y;
	scanf("%d%d",&x,&y);
	for(i=1;i<n;i++)
	{
		if(a[i]>=x && a[i]<=y)
		{
			if(a[n]-a[i]<=y && a[n]-a[i]>=x)
			{
				printf("%d\n",i+1);
				return 0;
			}
		}
	}
	puts("0");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define lld long long int
#define llu long long unsigned int
int compare(const void * a, const void * b){return *(lld *)a-*(lld *)b;}
//long long int readlint() {long long int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
//int readint() {int n=0,count=0,counti=0; char c;while(1){c=getchar_unlocked();if(c=='-')count=1;else if((c==' '||c=='\n'||c==EOF) && counti==1)break;else if(c>='0' && c<='9'){counti=1;n=(n<<3)+(n<<1)+c-'0';}}if(count==0)return n;else return -n;}
#define min(a,b)((a)>(b)?(b):(a))
#define max(a,b)((a)<(b)?(b):(a))
#define sort(arr,n) qsort(arr,n,sizeof(arr[0]),compare)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define su(n) scanf("%llu",&n)
#define ss(n) scanf("%s",n)
#define FOR(i,start,end) for(i=start; i<end; i++)
#define pdn(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pun(n) printf("%llu\n",n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define pu(n) printf("%llu",n)
#define pn puts("")
#define ps putchar_unlocked(' ')
void swap(int *x,int *y)
{
	*x=*x^*y;
	*y=*x^*y;
	*x=*x^*y;
}
int main()
{
	int i,j,k,n,t,m,a,b,c;
	sd(n);
	sd(m);
	int has[400000];
	for(i=0;i<n;i++)
		has[i]=-1;
	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(has[a]!=-1)
		{
			has[b]=(has[a]+1)%3;
			has[c]=(has[a]+2)%3;
		}
		else if(has[b]!=-1)
		{
			has[a]=(has[a]+1)%3;
			has[c]=(has[a]+2)%3;
		}
		else if(has[c]!=-1)
		{
			has[b]=(has[a]+1)%3;
			has[a]=(has[a]+2)%3;
		}
		else
		{
			has[a]=0;
			has[b]=1;
			has[c]=2;
		}
	}
	for(i=1;i<=n;i++)
		printf("%d ",has[i]+1);
	puts("");
	return 0;
}


#include <stdio.h>

void fill(int a, int b, int c, int color[])
{
    int i;
    for ( i = 1; i <= 3; i++ )
    {
        if ( color[a]!=i && color[b]!=i && color[c]!=i )
        {
            if ( color[a] == 0 )
                color[a] = i;
            else if ( color[b] == 0 )
                color[b] = i;
            else
                color[c] = i;
        }
    }
    return;
}

int main()
{
    int i;
    int n, m;
    int color[100005] = {0};
    scanf("%d%d",&n, &m);
    for ( i = 0; i < m; i++ )
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        fill(a, b, c, color);
    }
    printf("%d", color[1]);
    for ( i = 2; i <= n; i++ )
        printf(" %d", color[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>

void fill(int a, int b, int c, int color[])
{
    if ( color[a]&&color[b]&&color[c] )
        printf("error!\n");
    else if ( color[a]&&color[b] )
        color[c] = 6-color[a]-color[b];
    else if ( color[a]&&color[c] )
        color[b] = 6-color[a]-color[c];
    else if ( color[b]&&color[c] )
        color[a] = 6-color[b]-color[c];
    else if ( color[a] )
    {
        if ( color[a]==2 )
        {
            color[b] = 1;
            color[c] = 3;
        }
        else
        {
            color[b] = (6-color[a])/2;
            color[c] = 6-color[a]-color[b];
        }
    }
    else if ( color[b] )
    {
        if ( color[b]==2 )
        {
            color[a] = 1;
            color[c] = 3;
        }
        else
        {
            color[a] = (6-color[b])/2;
            color[c] = 6-color[a]-color[b];
        }
    }
    else if ( color[c] )
    {
        if ( color[c]==2 )
        {
            color[a] = 1;
            color[b] = 3;
        }
        else
        {
            color[a] = (6-color[c])/2;
            color[b] = 6-color[a]-color[c];
        }
    }
    else
    {
        color[a] = 1;
        color[b] = 2;
        color[c] = 3;
    }
    return;
}

int main()
{
    int i;
    int n, m;
    int color[100005] = {0};
    scanf("%d%d",&n, &m);
    for ( i = 0; i < m; i++ )
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        fill(a, b, c, color);
    }
    printf("%d", color[1]);
    for ( i = 2; i <= n; i++ )
        printf(" %d", color[i]);
    printf("\n");
    return 0;
}


/*
 * =====================================================================================
 *       Filename:  357B.c
 *    Description:  http://codeforces.com/contest/357/problem/B
 *
 *        Version:  1.0
 *        Created:  10/19/2013 02:04:10 PM
 *
 *         Author:  zhy (), zhy198606@gmail.com
 * =====================================================================================
 */

int Paint(int index, int* colors, int n, int *dances, int m)
{
    if (index == 3 * m)
        return 1;

    if (colors[dances[index]] != 0)
    {
        return Paint(index + 1, colors, n, dances, m);
    }

    int row = index / 3;
    int col = index % 3;
    int i = 1;

    int index1 = dances[row * 3 + (col + 1) % 3];
    int index2 = dances[row * 3 + (col + 2) % 3];

    for (i = 1; i <= 3; ++i)
    {
        if (colors[index1] == i || colors[index2] == i)
            continue;
        colors[dances[index]] = i;
        if (!Paint(index + 1, colors, n, dances, m))
        {
            colors[dances[index]] = 0;
        }
        else
        {
            return 1;
        }
    }

    return 0;
}

int main()
{
    int n, m, i, j;
    int dances[300001] = {0};
    int colors[100001] = {0};

    scanf("%d %d", &n, &m);

    for (i = 0; i < m; ++i)
        for (j = 0; j < 3; ++j)
        {
            scanf("%d", dances + i*3 + j);
        }

    Paint(0, colors, n, dances, m);
    for (i = 1; i <= n; ++i)
    {
        printf("%d ", colors[i]);
    }

    printf("\n");

}


/*
 * =====================================================================================
 *       Filename:  357B.c
 *    Description:  http://codeforces.com/contest/357/problem/B
 *
 *        Version:  1.0
 *        Created:  10/19/2013 02:04:10 PM
 *
 *         Author:  zhy (), zhy198606@gmail.com
 * =====================================================================================
 */

int Paint(int index, int* colors, int n, int *dances, int m)
{
    if (index == 3 * m)
        return 1;

    if (colors[dances[index]] != 0)
    {
        return Paint(index + 1, colors, n, dances, m);
    }

    int row = index / 3;
    int col = index % 3;
    int i = 1;

    int index1 = dances[row * 3 + (col + 1) % 3];
    int index2 = dances[row * 3 + (col + 2) % 3];

    for (i = 1; i <= 3; ++i)
    {
        if (colors[index1] == i || colors[index2] == i)
            continue;
        colors[dances[index]] = i;
        if (!Paint(index + 1, colors, n, dances, m))
        {
            colors[dances[index]] = 0;
        }
        else
        {
            return 1;
        }
    }

    return 0;
}

int main()
{
    int n, m, i, j;
    int dances[100001] = {0};
    int colors[100001] = {0};

    scanf("%d %d", &n, &m);

    for (i = 0; i < m; ++i)
        for (j = 0; j < 3; ++j)
        {
            scanf("%d", dances + i*3 + j);
        }

    Paint(0, colors, n, dances, m);
    for (i = 1; i <= n; ++i)
    {
        printf("%d ", colors[i]);
    }

    printf("\n");

}


#include<stdio.h>

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[m],i,j,dancers[n+1],x,y,z;
	for(i=0;i<n+1;i++)dancers[i]=0;
	for(i=0;i<m;i++){
		scanf("%d %d %d",&x,&y,&z);
		if(dancers[x]==0 && dancers[y]==0 && dancers[z]==0){
			dancers[x]=1;
			dancers[y]=2;
			dancers[z]=3;
		}
		else if((dancers[x]==1 || dancers[x]==2 || dancers[x]==3) && dancers[y]==0 && dancers[z]==0){
			int num=dancers[x];
			if(num==1){
				dancers[y]=2;
				dancers[z]=3;
			}
			if(num==2){
				dancers[y]=1;
				dancers[z]=3;
			}
			if(num==3){
				dancers[y]=2;
				dancers[z]=1;
			}
		}
		else if((dancers[y]==1 || dancers[y]==2 || dancers[y]==3) && dancers[x]==0 && dancers[z]==0){
			int num=dancers[y];
			if(num==1){
				dancers[x]=2;
				dancers[z]=3;
			}
			if(num==2){
				dancers[x]=1;
				dancers[z]=3;
			}
			if(num==3){
				dancers[x]=2;
				dancers[z]=1;
			}
		}
		else if((dancers[z]==1 || dancers[z]==2 || dancers[z]==3) && dancers[y]==0 && dancers[x]==0){
			int num=dancers[z];
			if(num==1){
				dancers[y]=2;
				dancers[x]=3;
			}
			if(num==2){
				dancers[y]=1;
				dancers[x]=3;
			}
			if(num==3){
				dancers[y]=2;
				dancers[x]=1;
			}
		}
	}
	for(i=1;i<n+1;i++)
		printf("%d ",dancers[i]);
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<string.h>
#define si(n) scanf("%d",&n)
#define rep(i,n) for(i=0;i<n;i++)
#define REP(i,a,b) for(i=a;i<b;i++)
#define pn printf("\n")
#define ps printf(" ")
#define pi(n) printf("%d",n)
#define pll(n) printf("%llu",n)
#define sll(n) scanf("%llu",&n)
#define ss(s) scanf("%s",s)
int cmp(const void *a,const void *b)
{
    return *(int*)a-*(int  *)b;
}

int main(){
int n,m,a[100005]={0},x,y,z,flag[4]={0},j,i;
si(n);si(m);
rep(i,m){si(x);si(y);si(z);
for(j=0;j<4;j++){flag[j]=0;}
if(a[x]){flag[a[x]]=-1;}

if(a[y]){flag[a[y]]=-1;}

if(a[z]){flag[a[z]]=-1;}

if(a[x]==0){for(j=1;j<4;j++){if(flag[j]==0){a[x]=j;flag[j]=-1;break;}}}
if(a[y]==0){for(j=1;j<4;j++){if(flag[j]==0){a[y]=j;flag[j]=-1;break;}}}

if(a[z]==0){for(j=1;j<4;j++){if(flag[j]==0){a[z]=j;flag[j]=-1;break;}}}}

for(i=1;i<=n;i++){pi(a[i]);ps;}
return 0;}


//In the name of God
#include <stdio.h>

#define MAXN 100100
int c[MAXN];

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  while(m--)
    {
      int a[3];
      scanf("%d%d%d",a,a+1,a+2);
      int used[4]={};
      used[c[a[1]]]=used[c[a[2]]]=used[c[a[0]]]=1;
      int i,j;
      for(i=0;i<3;++i)
	for(j=1;j<4;++j)
	  if(used[j]==0 && c[a[i]]==0)
	    {
	      c[a[i]]=j;
	      used[j]=1;
	    }
    }
  int i;
  for(i=1;i<=n;++i)
    printf("%d ",c[i]);
  printf("\n");
  return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define s second
#define f first
using namespace std;
int a,b,c,d,n,t;
int parent[10000006],FIXpar[10000006];
pair<int,int>inp[1000006];
vector<int>outp[7];
find (int x)
{
    if(parent[x]!=x)
    find(parent[x]);

    parent[x]=parent[parent[x]];
}
Union(int x,int y)
{
    int xset=parent[x];
    int yset=parent[y];
    parent[yset]=xset;
}
int main ()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
    }
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        inp[i].f=a;
        inp[i].s=b;

        find(b);
        find(a);

        if(parent[a]==parent[b])
        {
            t++;
            outp[1].pb(inp[i].f);
            outp[2].pb(inp[i].s);
        }
        Union(a,b);
        find(b);
        find(a);
    }
    FIXpar[parent[1]]=1;
    for(int i=1;i<n;i++)
    {
        if(!FIXpar[parent[i]])
        {
            outp[3].pb(parent[i]);
            outp[4].pb(parent[1]);
            FIXpar[parent[i]]=1;
        }
    }
    cout<<t<<endl;
    for(int i=0;i<t;i++)
    {
        cout<<outp[1][i]<<" "<<outp[2][i]<<" "<<outp[3][i]<<" "<<outp[4][i]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define s second
#define f first
using namespace std;
int a,b,c,d,n,t;
int parent[10000006],FIXpar[10000006];
pair<int,int>inp[1000006];
vector<int>outp[7];
find (int x)
{
    if(parent[x]!=x)
    find(parent[x]);

    parent[x]=parent[parent[x]];
}
Union(int x,int y)
{
    int xset=parent[x];
    int yset=parent[y];
    parent[yset]=xset;
}
int main ()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
    }
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        inp[i].f=a;
        inp[i].s=b;

        find(a);
        find(b);

        if(parent[a]==parent[b])
        {
            t++;
            outp[1].pb(inp[i].f);
            outp[2].pb(inp[i].s);
        }
        Union(a,b);
        find(b);
        find(a);
    }
    FIXpar[parent[1]]=1;
    for(int i=1;i<n;i++)
    {
        if(!FIXpar[parent[i]])
        {
            outp[3].pb(i);
            outp[4].pb(1);
            FIXpar[parent[i]]=1;
        }
    }
    cout<<t<<endl;
    for(int i=0;i<t;i++)
    {
        cout<<outp[1][i]<<" "<<outp[2][i]<<" "<<outp[3][i]<<" "<<outp[4][i]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int a,b,c,d,n;
int FIX[1000006],fix[1006][1006];
vector<int> vec[1000006],frn,tom,frv,tow;
void go(int x)
{
    FIX[x]=1;
    int k=0;
    while(k<vec[x].size())
    {
        if(FIX[vec[x][k]] && fix[x][vec[x][k]]==0 || fix[vec[x][k]][x]==0)
        {
            frn.pb(x);
            tom.pb(vec[x][k]);
        }
        if(FIX[vec[x][k]] && !(fix[x][vec[x][k]]==0 || fix[vec[x][k]][x]==0))
        {
            k++;
            continue;
        }
        else
        {
            fix[x][vec[x][k]]=1;
            fix[vec[x][k]][x]=1;
            go(vec[x][k]);
        }
        k++;
    }
}
int main ()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        vec[a].pb(b);
        vec[b].pb(a);
    }

    for(int i=1;i<=n;i++)
    {
        if(FIX[i]==0)
        {
            frv.pb(i);
            tow.pb(i);
            go(i);
        }
    }
    cout<<tow.size()-1<<endl;
    for(int i=0;i<tow.size()-1;i++)
    {
        cout<<frn[i]<<" "<<tom[i]<<" "<<frv[i]<<" "<<tow[i+1]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define s second
#define f first
using namespace std;
int a,b,c,d,n,t;
int uni[1000006],parent[10000006],FIXpar[10000006];
pair<int,int>inp[1000006];
vector<int>outp[7];
Union(int x,int y)
{
    int xset=parent[x];
    int yset=parent[y];
    parent[y]=xset;
}
int main ()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
    }
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        inp[i].f=a;
        inp[i].s=b;
        if(parent[inp[i].f]==parent[inp[i].s])
        {
            t++;
            outp[1].pb(inp[i].f);
            outp[2].pb(inp[i].s);
        }
        Union(a,b);
    }
    FIXpar[parent[1]]=1;
    for(int i=1;i<n;i++)
    {
        if(!FIXpar[parent[i]])
        {
            outp[3].pb(parent[i]);
            outp[4].pb(parent[i-1]);
            FIXpar[parent[i]]=1;
        }
    }
    cout<<t<<endl;
    for(int i=0;i<t;i++)
    {
        cout<<outp[1][i]<<" "<<outp[2][i]<<" "<<outp[3][i]<<" "<<outp[4][i]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int a,b,n,m,v,w;
int x[1000006],FIX[1000006];
int fix[1006][1006],ansfix[1006][1006];
vector<int>vec[100006],fri,toj,frn,tom;
void go(int x)
{
    FIX[x]=1;
    int k=0;
    while(k<vec[x].size())
    {
        if(FIX[vec[x][k]] && fix[vec[x][k]][x]==0)
        {
            if(ansfix[x][vec[x][k]]==0)
            {
                fri.pb(x);
                toj.pb(vec[x][k]);
            }
            ansfix[x][vec[x][k]]=1;
            ansfix[vec[x][k]][x]=1;
            k++;
            continue;
        }
        else
        if(FIX[vec[x][k]])
        {
            k++;
            continue;
        }
        else
        {
            fix[x][vec[x][k]]=1;
            fix[vec[x][k]][x]=1;
            go(vec[x][k]);
            k++;
            continue;
        }
    }
}
int main ()
{
    cin>>n;

    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        vec[a].pb(b);
        vec[b].pb(a);
    }
    for(int i=1;i<=n;i++)
    {
        if(!FIX[i])
        {
            frn.pb(i);
            tom.pb(i);
            go(i);
        }
    }
    cout<<fri.size()<<endl;
    for(int i=0;i<tom.size()-1;i++)
    {
        cout<<fri[i]<<" "<<toj[i]<<" "<<frn[i]<<" "<<tom[i+1]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int a,b,c,d,n;
int FIX[1000006];
vector<int> vec[1000006],frn,tom,frv,tow;
void go(int x)
{
    FIX[x]=1;
    int k=0;
    while(k<vec[x].size())
    {
        if(FIX[vec[x][k]])
        {
            frn.pb(x);
            tom.pb(vec[x][k]);
        }
        else
        {
            go(vec[x][k]);
        }
        k++;
    }
}
int main ()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        vec[a].pb(b);
    }

    for(int i=1;i<=n;i++)
    {
        if(FIX[i]==0)
        {
            frv.pb(i);
            tow.pb(i);
            go(i);
        }
    }
    cout<<frn.size()<<endl;
    for(int i=0;i<frn.size();i++)
    {
        cout<<frn[i]<<" "<<tom[i]<<" "<<frv[i]<<" "<<tow[i+1]<<endl;
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define s second
#define f first
using namespace std;
int a,b,c,d,n,t;
int parent[10000006],FIXpar[10000006];
pair<int,int>inp[1000006];
vector<int>outp[7];
find (int x)
{
    if(parent[x]!=x)
    find(parent[x]);

    parent[x]=parent[parent[x]];

}
Union(int x,int y)
{
    find(x);
    int xset=parent[x];
    find(y);
    int yset=parent[y];
    parent[yset]=xset;
}
int main ()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
    }
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        inp[i].f=a;
        inp[i].s=b;

        find(a);
        find(b);

        if(parent[a]==parent[b])
        {
            t++;
            outp[1].pb(inp[i].f);
            outp[2].pb(inp[i].s);
        }
        Union(a,b);
    }

    find(1);
    FIXpar[parent[1]]=1;
    for(int i=1;i<=n;i++)
    {
        find(i);

        if(!FIXpar[parent[i]])
        {
            outp[3].pb(i);
            outp[4].pb(1);
            FIXpar[parent[i]]=1;
        }
    }
    cout<<t<<endl;
    for(int i=0;i<t;i++)
    {
        cout<<outp[1][i]<<" "<<outp[2][i]<<" "<<outp[3][i]<<" "<<outp[4][i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited,used;
vector<int> adj[1001];
vector<pii> cycle;
int n;

vector<int> bfs(int s)
{
    visited[s]=true;
    vector<int> distance(n+1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
                q.push(u);
            }
           else
           {
               if(!used[u] && !used[x])
               {
                   cycle.push_back({u,x});
                   used[u]=true;
                   used[x]=true;
               }

           }
        }
    }
    return distance;
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    used.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited;
vector<int> adj[1001];
vector<pii> cycle;
int n;

vector<int> bfs(int s)
{
    visited[s]=true;
    vector<int> distance(n+1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
                q.push(u);
            }
           else
           {
               if(distance[u]==distance[x])
                   cycle.push_back({u,x});
           }
        }
    }
    return distance;
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

vector<int> adj[1001];
set<pii> cycle;
int parent[1001] = {};
int color[1001] = {};
int n,cc=0;

void dfs(int x)
{
    color[x] =1 ;
    for(int u : adj[x])
    {
       if(color[u] == 0)
       {
           parent[u] = x;
           color[u] = 1;
           dfs(u);
       }
       else
       {
           if(parent[x]!=u && color[u]==1)
           {
               cycle.insert({min(u,x),max(u,x)});
           }
       }
    }
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    vector<pii> ch;
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(color[i]==0)
        {
            if(i!=1)
                ch.push_back({1,i});
            color[i]=1;
            dfs(i);
        }
    }
    cout << cycle.size() << endl;
    int j=0;
    for(auto i : cycle)
    {
         cout << i.first << " " << i.second << " " << ch[j].first << " " << ch[j].second << endl;
         j++;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited,used;
vector<int> adj[1001];
vector<pii> cycle;
int d[1001] = {};
int n,cc=0;

void bfs(int s)
{
    visited[s]=true;
    vector<int> distance(n+1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
     //   cout << "checking by " << x << endl;
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
            //    cout << "Distance " << u << " is " << distance[u] << endl;
                q.push(u);
            }
           else
           {
               if((distance[u]==distance[x] || distance[u]==distance[x]+1 )&& (!used[u] || !used[x]))
               {
               //    cout << u << " " << x << endl;
                   cycle.push_back({u,x});
                   used[u]=true;
                   used[x]=true;
               }

           }
        }
    }
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    used.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
    int n,x,y;
    cin >> n ;
    vector<int> adj[n+1];
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       if(x>y)
         swap(x,y);
       adj[x].push_back(y);
    }
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        while(adj[i].size()>1)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(adj[j].size()==0 && adj[i].back()!=j)
                {
                    adj[j].push_back(adj[i].back());
                    ans.push_back({{i,adj[i].back()},{j,adj[i].back()}});
                    adj[i].pop_back();
                    break;
                }
            }
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited,used;
vector<int> adj[1001];
vector<pii> cycle;
int d[1001] = {};
int n,cc=0;

void bfs(int s)
{
    visited[s]=true;
    vector<int> distance;
    distance.assign(n+1,-1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
     //   cout << "checking by " << x << endl;
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
             //   cout << "Distance " << u << " is " << distance[u] << endl;
                q.push(u);
            }
           else
           {
               if(distance[u]>=distance[x]-1 && ( !used[u] || !used[x]))
               {
                 //  cout << u << " " << x << endl;
                   cycle.push_back({u,x});
                   used[u]=true;
                   used[x]=true;
               }

           }
        }
    }
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    used.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited,used;
vector<int> adj[1001];
vector<pii> cycle;
int d[1001] = {};
int n,cc=0;

void bfs(int s)
{
    visited[s]=true;
    vector<int> distance(n+1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
     //   cout << "checking by " << x << endl;
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
            //    cout << "Distance " << u << " is " << distance[u] << endl;
                q.push(u);
            }
           else
           {
               if(distance[u]==distance[x] || distance[u]==distance[x]+1 && !used[u] && !used[x])
               {
               //    cout << u << " " << x << endl;
                   cycle.push_back({u,x});
                   used[u]=true;
                   used[x]=true;
               }

           }
        }
    }
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    used.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bitset<1001> visited,used;
vector<int> adj[1001];
vector<pii> cycle;
int d[1001] = {};
int n,cc=0;

void bfs(int s)
{
    visited[s]=true;
    vector<int> distance;
    distance.assign(n+1,-1);
    distance[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
  //      cout << "checking by " << x << endl;
        q.pop();
        for(auto u : adj[x])
        {
            if(!visited[u])
            {
                visited[u]=true;
                distance[u]=distance[x]+1;
            //    cout << "Distance " << u << " is " << distance[u] << endl;
                q.push(u);
            }
           else
           {
               if(!(distance[u]>=distance[x]) && ( !used[u] || !used[x]))
               {
              //     cout << u << " " << x << endl;
                   cycle.push_back({u,x});
                   used[u]=true;
                   used[x]=true;
               }

           }
        }
    }
}

int main()
{
    int x,y;
    cin >> n ;
    for(int i=1;i<n;i++)
    {
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
    }
    visited.reset();
    used.reset();
    vector<pair<pii,pii>> ans;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(cycle.size()>0)
            {
                pii t = cycle.back();
                cycle.pop_back();
                ans.push_back({t,{t.first,i}});
            }
            bfs(i);
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;i<ans.size();i++)
    {
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    // cout << par_of_road << endl;
    if(par_of_road != 1){
      answers[j].u = 1;
      answers[j].v = par_of_road;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
      printf("%d %d %d %d\n", a.i,a.j,a.u,a.v);
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    make_set(u);
    make_set(v);
    Roads.push_back({ u,v });
  }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  int answer_cnt = 0;
  vector<Answer> answers;
  int to_delete_it = 0;
  for(auto &road: Roads){
    if (find_set(Roads[0].u) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, road.u });
      union_set(Roads[0].u,road.u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  cout << answer_cnt << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      answers.push_back({u, v, -1, -1});
    }
  }

  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = par_of_road;
      answers[j].v = 1;
      bool asd = union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
     cout << a.i << " " << a.j << " " << a.u << " " << a.v << endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    make_set(u);
    make_set(v);
    Roads.push_back({ u,v });
  }

  for (int u = 1; u <= N; u++) { ; }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  int answer_cnt = 0;
  vector<Answer> answers;
  int to_delete_it = 0;

  for(auto &road: Roads){
    if (find_set(Roads[0].u) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, road.u });
      union_set(Roads[0].u,road.u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  // Check cities without roads in the input
  for(int u = 1; u <= N; u++){
    if (to_delete[to_delete_it].u == 0) break;
    if (PAR[u] == 0) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, u });
      union_set(Roads[0].u,u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  cout << answer_cnt << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      // cout << "DROGA" << endl;
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = par_of_road;
      answers[j].v = 1;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
     cout << a.i << " " << a.j << " " << a.u << " " << a.v << endl;
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;
  for(int u = 1; u <= N; u++) { make_set(u); }

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    Roads.push_back({ u,v });
  }

  for (int u = 1; u <= N; u++) { ; }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  int answer_cnt = 0;
  vector<Answer> answers;
  int to_delete_it = 0;

  for(auto &road: Roads){
    if (find_set(1) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, 1, road.u });
      union_set(1,road.u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  // Check cities without roads in the input
  for(int u = 2; u <= N; u++){
    if (find_set(u) != find_set(1)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, find_set(1), u });
      union_set(find_set(1),u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  cout << answer_cnt << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    make_set(u);
    make_set(v);
    Roads.push_back({ u,v });
  }

  for (int u = 1; u <= N; u++) { ; }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  vector<Answer> answers;
  int to_delete_it = 0;

  for(auto &road: Roads){
    if (find_set(Roads[0].u) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, road.u });
      union_set(Roads[0].u,road.u);
      to_delete_it++;
    }
  }

  // Check cities without roads in the input
  for(int u = 1; u <= N; u++){
    for(int v = u+1; v <= N; v++) {
      if (find_set(u) != find_set(v)) {
        answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, u, v });
        union_set(v,u);
        to_delete_it++;
      }
    }
  }

  cout << answers.size() << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      answers.push_back({u, v, -1, -1});
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
    return 0;
  }
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = par_of_road;
      answers[j].v = 1;
      bool asd = union_set(1,par_of_road);
      j++;
    }
  }

  cout << answers.size() << endl;
  for(answer &a: answers){
    cout << a.i << " " << a.j << " " << a.u << " " << a.v << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    make_set(u);
    make_set(v);
    Roads.push_back({ u,v });
  }

  for (int u = 1; u <= N; u++) { ; }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  int answer_cnt = 0;
  vector<Answer> answers;
  int to_delete_it = 0;

  for(auto &road: Roads){
    if (find_set(Roads[0].u) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, road.u });
      union_set(Roads[0].u,road.u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  // Check cities without roads in the input
  for(int u = 1; u <= N; u++){
    if (PAR[u] == 0) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, u });
      union_set(Roads[0].u,u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  cout << answer_cnt << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = PAR[r.u];
    if(par_of_road != 1){
      answers[j].u = 1;
      answers[j].v = par_of_road;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
      printf("%d %d %d %d", a.i,a.j,a.u,a.v);
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      // cout << "DROGA" << endl;
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = par_of_road;
      answers[j].v = 1;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
      cout << answers.size() << endl;
    for(answer &a: answers){
      printf("%d %d %d %d\n", a.i,a.j,a.u,a.v);
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = 1;
      answers[j].v = par_of_road;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
      printf("%d %d %d %d", a.i,a.j,a.u,a.v);
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Road { int u, v; };
struct Answer {
  int u, v, n, m;
  string toString() {
    return to_string(u) +  " " + to_string(v) + " " + to_string(n) + " " + to_string(m);
  }
};

const int SIZE = 2 * 1e3;
int PAR[SIZE] = { 0 };

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

int main(){
  int N;
  cin >> N;
  vector<Road> Roads;

  for(int i = 0; i < N-1; i++){
    int u,v;
    cin >> u >> v;
    make_set(u);
    make_set(v);
    Roads.push_back({ u,v });
  }

  for (int u = 1; u <= N; u++) { ; }

  vector<Road> to_delete;
  for(auto &road: Roads){
    if (find_set(road.u) == find_set(road.v)) {
      to_delete.push_back({ road.u, road.v });
    }else {
      union_set(road.u, road.v);
    }
  }

  int answer_cnt = 0;
  vector<Answer> answers;
  int to_delete_it = 0;

  for(auto &road: Roads){
    if (find_set(Roads[0].u) != find_set(road.u)) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, road.u });
      union_set(Roads[0].u,road.u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  // Check cities without roads in the input
  for(int u = 1; u <= N; u++){
    if (to_delete.size()){
      if (to_delete[to_delete_it].u == 0) break;
    }
    if (PAR[u] == 0) {
      answers.push_back({ to_delete[to_delete_it].u, to_delete[to_delete_it].v, Roads[0].u, u });
      union_set(Roads[0].u,u);
      answer_cnt++;
      to_delete_it++;
    }
  }

  cout << answer_cnt << endl;
  for(auto &answer: answers){
    cout << answer.toString() << endl;
  }
  return 0;
}