#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e4 + 5;
int head[N], fa[N], deep[N], pos[N];
int tot = 1, val[N];
struct node {
  int v, nxt, id;
} edge[N];
struct Node {
  int u, v, w;
} e[N];
bool cmp(Node a, Node b) { return a.w > b.w; }
void add(int u, int v, int i) {
  edge[tot].v = v;
  edge[tot].id = i;
  edge[tot].nxt = head[u];
  head[u] = tot++;
}
void dfs(int u, int fat) {
  for (int i = head[u]; i != -1; i = edge[i].nxt) {
    int v = edge[i].v;
    if (v == fat) continue;
    pos[edge[i].id] = v;
    fa[v] = u;
    deep[v] = deep[u] + 1;
    dfs(v, u);
  }
}
int main() {
  int n, m;
  scanf("%d", &n);
  memset(head, -1, sizeof head);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v, i);
    add(v, u, i);
  }
  deep[1] = 1;
  dfs(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  }
  sort(e + 1, e + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    bool flag = false;
    if (deep[u] < deep[v]) swap(u, v);
    while (deep[u] != deep[v]) {
      if ((!val[u]) || val[u] == w) {
        val[u] = w;
        flag = true;
      }
      u = fa[u];
    }
    while (u != v) {
      if ((!val[u]) || val[u] == w) {
        val[u] = w;
        flag = true;
      }
      if ((!val[v]) || val[v] == w) {
        val[v] = w;
        flag = true;
      }
      u = fa[u], v = fa[v];
    }
    if (!flag) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (val[pos[i]]) {
      printf("%d ", val[pos[i]]);
    } else {
      printf("1000000 ");
    }
  }
  return 0;
}
