#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int n, m;
vector<pair<int, int> > g[maxn];
struct edge {
  int u, v, w;
} e[maxn];
bool cmp(edge x, edge y) { return x.w < y.w; }
int pre[maxn][maxn][2];
int ans[maxn];
void dfs(int u, int fa, int root, int id) {
  pre[root][u][0] = id;
  pre[root][u][1] = fa;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i].first, t = g[u][i].second;
    if (v == fa) continue;
    dfs(v, u, root, t);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(pair<int, int>(v, i));
    g[v].push_back(pair<int, int>(u, i));
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, 0, i, 0);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  }
  sort(e, e + m, cmp);
  for (int i = 0; i < m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    for (int j = v; j != u; j = pre[u][j][1]) {
      int id = pre[u][j][0];
      ans[id] = w;
    }
  }
  for (int i = 0; i < m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    int mi = inf;
    for (int j = v; j != u; j = pre[u][j][1]) {
      int id = pre[u][j][0];
      if (ans[id] == 0)
        ans[id] = 1e6;
      else {
        mi = min(mi, ans[id]);
      }
    }
    if (mi != w) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == 0) ans[i] = 1e6;
    printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}
