#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
vector<int> g[100004];
int col[100004];
int dist[100004];
void bfs(int v, int d, int c) {
  fill(dist, dist + 100004, 1e7);
  queue<int> q;
  dist[v] = 0;
  q.push(v);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (dist[x] == d) break;
    for (int i = 0; i < g[x].size(); i++) {
      int n = g[x][i];
      if (dist[n] > dist[x] + 1) {
        dist[n] = dist[x] + 1;
        q.push(n);
        if (dist[n] <= d) col[x] = 1;
      }
    }
  }
}
int main() {
  memset(col, 0, sizeof(col));
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int v, d, c;
    cin >> v >> d >> c;
    bfs(v, d, c);
  }
  for (int i = 1; i <= N; i++) cout << col[i] << endl;
  return 0;
}
