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

char getch()
{
	static char buf[1 << 14], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 14, stdin), p1 == p2) ? EOF : *p1++;
}

void read(int &x)
{
	x = 0;
	char c = getch();
	while(c < '0' || c > '9') c = getch();
	while(c >= '0' && c <= '9')
	{
		x = x * 10 + (c - '0');
		c = getch();
	}
}

int n, m, cnt;
int head[100001], vis[100001];
struct node
{
	int v, w, next;
}e[500003];

void add(int u, int v, int w)
{
	e[++cnt].v = v;
	e[cnt].w = w;
	e[cnt].next = head[u];
	head[u] = cnt;
}

void dfs(int u)
{
	for(int i = head[u]; i; i = e[i].next)
	{
		int v = e[i].v, w = e[i].w;
		if(vis[v]) continue;
		if(vis[u] == w) vis[v] = w % n + 1;
		else vis[v] = w;
		dfs(v);
	}
}

int main()
{
	read(n); read(m);
	int x, y, z;
	for(int i = 1; i <= m; ++i)
	{
		read(x); read(y); read(z);
		add(x, y, z); add(y, x, z);
	}
	vis[1] = 1;	dfs(1);
	int flag = 0;
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
		{
			flag = 1;
			break;
		}
	if(flag) cout << "No" << endl;
	else
	{
		for(int i = 1; i <= n; ++i)
			printf("%d\n", vis[i]);
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	char s,t; cin >> s >> t;
	if(s == 'Y'){
		if(t == 'a'){
			cout << 'A' << endl;
		}else if(t == 'b'){
			cout << 'B' << endl;
		}else{
			cout << 'C' << endl;
		}
	}else{
		cout << t << endl;
	}
}