#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int MOD = 1e9 + 7;
const int MASK = (1 << 24) + 5;
const double PI = 2 * acos(0.0);
struct Query {
  int u, v, mn;
  Query() { u = v = mn = 0; }
};
vector<int> g[N];
Query q[N], edge[N];
int ans, cost[N][N];
bool dfs1(int u, int p, int des, int mn) {
  if (u == des) {
    return 1;
  }
  for (auto v : g[u])
    if (v != p) {
      if (dfs1(v, u, des, mn)) {
        cost[u][v] = cost[v][u] = mn;
        return 1;
      }
    }
  return 0;
}
bool dfs2(int u, int p, int des) {
  if (u == des) {
    return 1;
  }
  for (auto v : g[u])
    if (v != p) {
      if (dfs2(v, u, des)) {
        ans = min(ans, cost[u][v]);
        return 1;
      }
    }
  return 0;
}
bool cmp(Query x, Query y) { return x.mn < y.mn; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
    edge[i].u = u, edge[i].v = v;
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &q[i].u, &q[i].v, &q[i].mn);
  }
  sort(q, q + m, cmp);
  for (int i = 0; i < m; i++) {
    dfs1(q[i].u, 0, q[i].v, q[i].mn);
  }
  bool ok = 1;
  for (int i = 0; i < m; i++) {
    ans = 1e9;
    int x = dfs2(q[i].u, 0, q[i].v);
    if (ans != q[i].mn) {
      ok = 0;
      break;
    }
  }
  if (!ok) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int x = cost[edge[i].u][edge[i].v];
    if (x == 0) {
      x = 1e6;
    }
    printf("%d ", x);
  }
  puts("");
  return 0;
}
