#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int M = 1100000;
const long long mod = 1e9 + 7;
int n, m;
vector<pair<int, int> > g[N];
int edge[N];
int col[N], dep[N];
int val[N], f[N];
void dfs(int x, int fa) {
  f[x] = fa;
  dep[x] = dep[fa] + 1;
  for (auto p : g[x]) {
    int y = p.first, id = p.second;
    if (y == fa) continue;
    edge[y] = id;
    dfs(y, x);
  }
}
struct query {
  int x, y, w;
  friend bool operator<(query a, query b) { return a.w < b.w; }
} a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(make_pair(y, i)), g[y].push_back(make_pair(x, i));
  }
  dfs(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) val[i] = 1e6;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].w);
    b[i] = a[i];
  }
  sort(a + 1, a + 1 + m);
  for (int i = 1; i <= m; i++) {
    int nx = a[i].x, ny = a[i].y;
    while (dep[nx] != dep[ny]) {
      if (dep[nx] > dep[ny])
        val[edge[nx]] = a[i].w, nx = f[nx];
      else
        val[edge[ny]] = a[i].w, ny = f[ny];
    }
    while (nx != ny) {
      val[edge[nx]] = a[i].w, nx = f[nx];
      val[edge[ny]] = a[i].w, ny = f[ny];
    }
  }
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    int nx = b[i].x, ny = b[i].y;
    int mn = 1e9;
    while (dep[nx] != dep[ny]) {
      if (dep[nx] > dep[ny])
        mn = min(mn, val[edge[nx]]), nx = f[nx];
      else
        mn = min(mn, val[edge[ny]]), ny = f[ny];
    }
    while (nx != ny) {
      mn = min(mn, val[edge[nx]]), nx = f[nx];
      mn = min(mn, val[edge[ny]]), ny = f[ny];
    }
    if (mn != b[i].w) flag = 1;
  }
  if (flag)
    printf("-1\n");
  else {
    for (int i = 1; i < n; i++) printf("%d ", val[i]);
  }
  return 0;
}
