#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next;
} e[1000010];
struct Q {
  int a, b, v;
} q[1000010];
int head[1000010], num;
int col[1000010];
int n, m;
void addedge(int a, int b) {
  e[++num].to = b;
  e[num].next = head[a];
  head[a] = num;
}
bool cmp(Q a, Q b) { return a.v < b.v; }
void dfs(int u, int to, int color, bool &opt, int fa) {
  if (u == to) {
    opt = 1;
    return;
  }
  for (int i = head[u]; i; i = e[i].next) {
    if (fa ^ e[i].to) {
      dfs(e[i].to, to, color, opt, u);
      if (opt == 1) {
        col[(i + 1) / 2] = color;
        return;
      }
    }
  }
}
int checkdfs(int u, int to, bool &opt, int fa) {
  if (u == to) {
    opt = 1;
    return 0x3f3f3f3f;
  }
  for (int i = head[u]; i; i = e[i].next) {
    if (fa ^ e[i].to) {
      int now = checkdfs(e[i].to, to, opt, u);
      if (opt == 1) {
        return min(col[(i + 1) / 2], now);
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) col[i] = 1;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &q[i].a, &q[i].b, &q[i].v);
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    bool opt = 0;
    dfs(q[i].a, q[i].b, q[i].v, opt, q[i].a);
  }
  for (int i = 1; i <= m; i++) {
    bool opt = 0;
    if (checkdfs(q[i].a, q[i].b, opt, q[i].a) != q[i].v) {
      printf("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n - 1; i++) printf("%d ", col[i]);
}
