/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju */
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <deque>
#include <climits>
#include <complex>
#include <bitset>
#include <limits>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for (; e > 0; e >>= 1) {
        if (e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if (b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for (; e > 0; e >>= 1) {
        if (e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a, T b, T c) {
    if (((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1; //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000ll
#define md 1000000007
#define maxp 2050180000
#define LO(X) X[p][k]
#define base 29

typedef pair<int , int > P;
typedef vector<int> V;
//////////////////////////
/////////////////////////

int n,m;

vector<int>v[mx+2];

int main() {

    I2(n,m);
    fr(i,1,m) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }
    queue<P >pq;

    P vis[n+2][20];
    SETR(vis);
    int q;
    I(q);
    bool tr[n+2][10];
    SET(tr);
    fr(i,1,q) {
        int x,y,z;
        I3(x,y,z);
        pq.push(mk(x,y));
        tr[x][y]=1;
        vis[x][y]=mk(i,z);
    }

    P co[n+2];
    SET(co);

    while(!pq.empty()) {
        P t=pq.front();
        tr[t.x][t.y]=0;
        pq.pop();
        if(co[t.x].x<vis[t.x][t.y].x) {
            co[t.x]=vis[t.x][t.y];
        }
        if(t.y<=0)continue;
        for(int i=0; i<v[t.x].size(); i++) {

            int f=v[t.x][i];
            int t1=t.y-1;

            if(co[f].x<vis[t.x][t.y].x) {
                co[f]=vis[t.x][t.y];
            }
            bool fl=0;
            for(int op=t1; op<=10; op++) {
                if(vis[f][op].x>vis[t.x][t.y].x)fl=1;
            }
            if(fl==1||t1<=0)continue;
            if(vis[f][t1].x<vis[t.x][t.y].x) {
                    tr[f][t1]=1;
                vis[f][t1]=vis[t.x][t.y];
                pq.push(mk(f,t1));
            }
        }

    }
    for(int i=1; i<=n; i++) {
        PI(co[i].y),NL;
    }


    return 0;
}


Measured memory_bytes: 30712