#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5) + 10;
struct Node {
  int l, r, v, p;
} qr[MAX];
vector<pair<int, int> > mat[MAX];
int lev[MAX], paa[MAX], val[MAX], path[MAX];
void dfs(int p, int pa) {
  for (pair<int, int> ed : mat[p]) {
    int x = ed.first, v = ed.second;
    if (x == pa) continue;
    lev[x] = lev[p] + 1;
    paa[x] = p;
    path[x] = v;
    dfs(x, p);
  }
}
int miin(int u, int v) { return (min(u, v) == -1) ? max(u, v) : min(u, v); }
int main() {
  ios::sync_with_stdio(false);
  int n, v, u, q, c;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    mat[u].push_back({v, i});
    mat[v].push_back({u, i});
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> qr[i].l >> qr[i].r >> qr[i].v;
  }
  sort(qr, qr + q, [](Node x, Node y) { return x.v < y.v; });
  dfs(1, 1);
  for (int i = 0; i < q; i++) {
    u = qr[i].l;
    v = qr[i].r;
    c = qr[i].v;
    while (true) {
      if (u == v) break;
      if (lev[v] > lev[u]) {
        val[path[v]] = c;
        v = paa[v];
      } else {
        val[path[u]] = c;
        u = paa[u];
      }
    }
  }
  for (int i = 0; i < q; i++) {
    u = qr[i].l;
    v = qr[i].r;
    c = -1;
    while (true) {
      if (u == v) break;
      if (lev[v] > lev[u]) {
        c = miin(val[path[v]], c);
        v = paa[v];
      } else {
        c = miin(c, val[path[u]]);
        u = paa[u];
      }
    }
    if (c != qr[i].v) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << max(1, val[i]) << " ";
  }
  return 0;
}
