#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
const int MAXN = 1e6 + 5;
int n, m, t;
int flag;
struct NODE {
  int a, b, c;
} q[MAXN];
vector<int> to[MAXN];
int ans[MAXN];
int cmp(NODE a, NODE b) { return a.c > b.c; }
int ma[5005][5005];
int dfs(int u, int f, int ed, int x, int index) {
  if (u == ed) {
    if (f == 0) return 1;
    if (!ans[ma[u][f]] || ans[ma[u][f]] == x)
      flag = 1, ans[ma[u][f]] = x;
    else if (flag == 0 && ans[ma[u][f]] > x)
      flag = -1;
    return 1;
  }
  int tmp = 0;
  for (int i = 0; i < to[u].size(); i++) {
    int v = to[u][i];
    if (v == f) continue;
    tmp |= dfs(v, u, ed, x, index);
    if (tmp == 1) {
      if (f == 0) return 1;
      if (!ans[ma[u][f]] || ans[ma[u][f]] == x)
        flag = 1, ans[ma[u][f]] = x;
      else if (flag == 0 && ans[ma[u][f]] > x)
        flag = -1;
    }
  }
  return tmp;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    to[a].push_back(b);
    to[b].push_back(a);
    ma[a][b] = ma[b][a] = i;
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    q[i] = {a, b, c};
  }
  sort(q + 1, q + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    flag = 0;
    dfs(q[i].a, 0, q[i].b, q[i].c, i);
    if (flag == -1) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    if (ans[i])
      cout << ans[i] << ' ';
    else
      cout << 1 << ' ';
  }
}
