import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class A{
	int v, d, c;
	this(int v, int d, int c){
		this.v = v;
		this.d = d;
		this.c = c;
		}
	}

void main(){
	int n = read.to!int;
	int m = read.to!int;
	
	Graph g = new Graph(n);
	for(int i = 0; i < m; i ++) g.setEdge(read.to!int, read.to!int);
	
	int q = read.to!int;
	A[] as;
	for(int i = 0; i < q; i ++) as ~= new A(read.to!int, read.to!int, read.to!int);
	
	foreach_reverse(i, a; as) g.nodes[a.v].paint(a.d, a.c, cast(long) i);
	
	for(int i = 1; i <= n; i ++) g.nodes[i].value.writeln;
	}




string read(){
	static string[] ss;
	while(!ss.length) ss = readln.chomp.split;
	string res = ss[0];
	ss.popFront;
	return res;
	} 

class Graph{
	Node[long] nodes;
	this(long nodeCount){
		for(int i = 0; i < nodeCount; i ++) addNode(i + 1);
		}
	void addNode(long id){
		if(id !in nodes) nodes[id] = new Node(id);
		}
	void setEdge(long id1, long id2){
		nodes[id1].addEdge(nodes[id2]);
		}
	void adopt(long id1, long id2){
		nodes[id1].addKid(nodes[id2]);
		}
	}

class Node{
	long id;
	long value;
	Node[long] adjnodes;
	Node[long] kids;
	Node parent;
	int paintid = -100;
	bool isPainted = false;
	this(long id){
		this.id = id;
		}
	this(long id, long value){
		this.id = id;
		this.value = value;
		}
	void addEdge(Node nd){
		this.adjnodes[nd.id] = nd;
		nd.adjnodes[this.id] = this;
		}
	void addKid(Node nd){
		this.kids[nd.id] = nd;
		nd.parent = this;
		}
	
	void paint(int d, int c, int id){
		this.paintid = id;
		if(d > 0){
			foreach(nd; adjnodes){
				if(nd.paintid != id) nd.paint(d - 1, c, id);
				}
			}
		if(!this.isPainted){
			this.value = c;
			this.isPainted = true;
			}
		}
	
	} 