#include <bits/stdc++.h>
using namespace std;
int n;
int m;
void bfs(int u, vector<pair<int, int>> &p,
         vector<vector<pair<int, int>>> &adj) {
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto as : adj[cur]) {
      int v = as.first;
      if (v == p[cur].first) continue;
      int e = as.second;
      p[v].first = cur;
      p[v].second = e;
      q.push(v);
    }
  }
}
int main() {
  scanf("%d", &n);
  vector<vector<pair<int, int>>> adj(n + 1);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
  }
  vector<vector<pair<int, int>>> pre(n + 1, vector<pair<int, int>>(n + 1));
  for (int i = 1; i <= n; ++i) {
    pre[i][i] = make_pair(0, 0);
    bfs(i, pre[i], adj);
  }
  scanf("%d", &m);
  vector<int> val(n, 0);
  vector<vector<int>> query(m + 1, vector<int>(3, 0));
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", &query[i][0], &query[i][1], &query[i][2]);
  }
  for (int i = 1; i <= m; ++i) {
    int u = query[i][0];
    int v = query[i][1];
    int f = query[i][2];
    while (true) {
      int pree = pre[u][v].second;
      int prev = pre[u][v].first;
      val[pree] = max(val[pree], f);
      v = prev;
      if (v == u) break;
    }
  }
  for (int i = 1; i <= m; ++i) {
    int u = query[i][0];
    int v = query[i][1];
    int f = query[i][2];
    int mx = 1000000 + 10;
    while (true) {
      int pree = pre[u][v].second;
      int prev = pre[u][v].first;
      mx = min(mx, val[pree]);
      v = prev;
      if (v == u) break;
    }
    if (mx != f) {
      printf("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n - 1; ++i) {
    if (val[i] == 0)
      printf("100 ");
    else
      printf("%d ", val[i]);
  }
  return 0;
}
