#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
int n, m;
int id[N][N];
struct edge {
  int v, nxt;
} e[N << 1];
int head[N], ecnt;
void ad(int u, int v) {
  e[++ecnt].v = v;
  e[ecnt].nxt = head[u];
  head[u] = ecnt;
}
struct querys {
  int a, b, mn;
} q[N];
bool cmp(const querys &x, const querys &y) { return x.mn > y.mn; }
int pre[N];
vector<int> vec[N];
int num[N], tot;
int S, T;
void dfs(int u, int fa) {
  if (u == T) return;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    pre[v] = u;
    dfs(v, u);
  }
}
int ans[N];
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    ad(x, y), ad(y, x);
    id[x][y] = id[y][x] = i;
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &q[i].a, &q[i].b, &q[i].mn);
    if (q[i].a > q[i].b) swap(q[i].a, q[i].b);
    num[++tot] = q[i].mn;
  }
  sort(num + 1, num + tot + 1, greater<int>());
  int mx = num[tot];
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; ++i) {
    memset(pre, -1, sizeof(pre));
    S = q[i].a, T = q[i].b;
    dfs(S, 0);
    bool flag = false;
    int now = 9999999;
    for (int j = T; pre[j] != -1; j = pre[j]) {
      int u = j, v = pre[j];
      if (ans[id[u][v]]) {
        now = min(ans[id[u][v]], now);
        continue;
      }
      ans[id[u][v]] = q[i].mn;
      now = q[i].mn;
      flag = 1;
    }
    if (!flag && q[i].mn != now) return puts("-1"), 0;
  }
  for (int i = 1; i < n; ++i)
    if (!ans[i]) ans[i] = 1e6;
  for (int i = 1; i < n; ++i) cout << ans[i] << " ";
  return 0;
}
