#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
struct Edge {
  int to, nxt;
} edge[maxn << 1];
int n, m, tot, root;
int head[maxn];
int x[maxn], y[maxn], fa[maxn][maxn], ans[maxn][maxn];
int u[maxn], v[maxn], d[maxn];
inline void addedge(int u, int v) {
  edge[++tot].to = v, edge[tot].nxt = head[u], head[u] = tot;
}
inline void dfs(int u, int f) {
  fa[root][u] = f;
  for (int i = head[u], v; i; i = edge[i].nxt) {
    v = edge[i].to;
    if (v != f) dfs(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    addedge(x[i], y[i]), addedge(y[i], x[i]);
  }
  for (int i = 1; i <= n; i++) root = i, dfs(i, 0);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u[i], &v[i], &d[i]);
    int a = u[i], b = v[i];
    int fb = fa[a][b];
    while (fb != a) {
      ans[fb][b] = ans[b][fb] = max(ans[fb][b], d[i]);
      b = fb;
      fb = fa[a][fb];
    }
    ans[fb][b] = ans[b][fb] = max(ans[fb][b], d[i]);
  }
  bool flag = 1;
  for (int i = 0; i < m && flag; i++) {
    int a = u[i], b = v[i];
    int fb = fa[a][b];
    int MIN = 0x3f3f3f3f;
    while (fb != a) {
      MIN = min(ans[fb][b], MIN);
      b = fb;
      fb = fa[a][fb];
    }
    MIN = min(ans[fb][b], MIN);
    if (MIN != d[i]) flag = 0;
  }
  if (flag) {
    for (int i = 1; i < n; i++) {
      if (!ans[x[i]][y[i]]) ans[x[i]][y[i]] = 1;
      printf("%d ", ans[x[i]][y[i]]);
    }
  } else
    printf("-1\n");
  return 0;
}
