#include <bits/stdc++.h>
using namespace std;
void dfs(int u, int p, int **memo, int *lev, int log, vector<int> *g) {
  memo[u][0] = p;
  for (int i = 1; i <= log; i++) memo[u][i] = memo[memo[u][i - 1]][i - 1];
  for (int v : g[u]) {
    if (v != p) {
      lev[v] = lev[u] + 1;
      dfs(v, u, memo, lev, log, g);
    }
  }
}
int lca2(int u, int v, int log, int *lev, int **memo, int **gar) {
  int ans = 1000000;
  if (lev[u] < lev[v]) swap(u, v);
  for (int i = log; i >= 0; i--)
    if ((lev[u] - (1 << i)) >= lev[v]) {
      ans = min(ans, gar[u][i]);
      u = memo[u][i];
    }
  if (u == v) {
    return ans;
  }
  for (int i = log; i >= 0; i--) {
    if (memo[u][i] != memo[v][i]) {
      ans = min(gar[u][i], ans);
      ans = min(gar[v][i], ans);
      u = memo[u][i];
      v = memo[v][i];
    }
  }
  ans = min(gar[u][0], ans);
  ans = min(gar[v][0], ans);
  return ans;
}
void lca1(int u, int v, int log, int *lev, int **memo, int **gar, int &y) {
  if (lev[u] < lev[v]) swap(u, v);
  for (int i = log; i >= 0; i--)
    if ((lev[u] - (1 << i)) >= lev[v]) {
      gar[u][i] = max(y, gar[u][i]);
      u = memo[u][i];
    }
  if (u == v) {
    return;
  }
  for (int i = log; i >= 0; i--) {
    if (memo[u][i] != memo[v][i]) {
      gar[u][i] = max(gar[u][i], y);
      gar[v][i] = max(gar[v][i], y);
      u = memo[u][i];
      v = memo[v][i];
    }
  }
  gar[u][0] = max(gar[u][0], y);
  gar[v][0] = max(gar[v][0], y);
}
int main() {
  int n, m;
  cin >> n;
  vector<int> g[n + 1];
  int log = (int)ceil(log2(n));
  int **memo = new int *[n + 1], **gar = new int *[n + 1];
  for (int i = 0; i < n + 1; i++) {
    memo[i] = new int[log + 1];
    gar[i] = new int[log + 1];
  }
  int *lev = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= log; ++j) {
      memo[i][j] = -1;
      gar[i][j] = 0;
    }
  }
  vector<pair<int, int>> b;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    b.push_back(make_pair(u, v));
  }
  dfs(1, 1, memo, lev, log, g);
  cin >> m;
  vector<pair<pair<int, int>, int>> q(m);
  for (int i = 0; i < m; ++i) {
    cin >> q[i].first.first >> q[i].first.second >> q[i].second;
    lca1(q[i].first.first, q[i].first.second, log, lev, memo, gar, q[i].second);
  }
  for (int i = log; i; --i) {
    for (int j = 1; j <= n; ++j) {
      gar[j][i - 1] = max(gar[j][i - 1], gar[j][i]);
      gar[memo[j][i - 1]][i - 1] = max(gar[memo[j][i - 1]][i - 1], gar[j][i]);
    }
  }
  for (int i = 1; i <= n; ++i)
    if (gar[i][0] == 0) gar[i][0] = 1000000;
  for (int i = 1; i <= log; ++i) {
    for (int j = 1; j <= n; ++j) {
      gar[j][i] = min(gar[memo[j][i - 1]][i - 1], gar[j][i - 1]);
    }
  }
  for (int i = 0; i < m; ++i) {
    if (lca2(q[i].first.first, q[i].first.second, log, lev, memo, gar) !=
        q[i].second) {
      cout << "-1\n";
      return 0;
    }
  }
  --n;
  for (int i = 0; i < n; ++i)
    cout << lca2(b[i].first, b[i].second, log, lev, memo, gar) << " ";
  return 0;
}
