#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
int dp[11][111111];
vector<int>pat[111111];
int col[111111];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--;
		dp[10 - zb][za] = max(dp[10 - zb][za], i + 1);
		col[i + 1] = zc;
	}
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < num; j++)
		{
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			for (int k = 0; k < pat[j].size(); k++)
			{
				dp[i + 1][pat[j][k]] = max(dp[i + 1][pat[j][k]], dp[i][j]);
			}
		}
	}
	for (int i = 0; i < num; i++)printf("%d\n", col[dp[10][i]]);
}