#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10, inf = 0x3f3f3f3f;
int n;
struct node {
  int u, v, w;
} a[N];
vector<int> vec[N];
int mx[N];
struct edge {
  int id, v;
};
vector<edge> G[N];
int ans[N];
int mxx, mi;
int dfs(int u, int f, int tar, int w) {
  if (u == tar) return 1;
  for (int i = 0; i < G[u].size(); ++i) {
    edge now = G[u][i];
    if (now.v == f) continue;
    if (dfs(now.v, u, tar, w)) {
      mx[now.id] = max(mx[now.id], w);
      return 1;
    }
  }
  return 0;
}
int dfs1(int u, int f, int tar) {
  if (u == tar) return 1;
  for (int i = 0; i < G[u].size(); ++i) {
    edge now = G[u][i];
    if (now.v == f) continue;
    if (dfs1(now.v, u, tar)) {
      mi = min(mx[now.id], mi);
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back({i, v});
    G[v].push_back({i, u});
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w);
    dfs(a[i].u, -1, a[i].v, a[i].w);
  }
  int f = 1;
  for (int i = 1; i <= m && f; ++i) {
    mi = inf;
    dfs1(a[i].u, -1, a[i].v);
    if (mi != a[i].w) {
      f = 0;
    }
  }
  if (!f) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i < n; ++i) {
    if (mx[i] == 0)
      printf("1 ");
    else
      printf("%d ", mx[i]);
  }
}
