#include <bits/stdc++.h>
using namespace std;
constexpr int const maxn = 5120;
int d[maxn], fa[maxn], f[maxn], g[maxn], id[maxn];
vector<pair<int, int>> adj[maxn];
void dfs(int u, int p, int i) {
  d[u] = d[p] + 1;
  fa[u] = p;
  id[u] = i;
  for (auto const& e : adj[u])
    if (e.first != p) dfs(e.first, u, e.second);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i != n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].emplace_back(v, i);
    adj[v].emplace_back(u, i);
    f[i + 1] = 1000000;
  }
  dfs(1, 0, 0);
  int m;
  cin >> m;
  vector<pair<int, pair<int, int>>> line(m);
  for (int i = 0; i != m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    if (d[u] < d[v]) swap(u, v);
    line[i] = make_pair(w, make_pair(u, v));
  }
  sort(line.begin(), line.end());
  for (int i = 0; i != m; ++i) {
    int u = line[i].second.first, v = line[i].second.second, w = line[i].first;
    while (d[u] > d[v]) {
      f[u] = w;
      u = fa[u];
    }
    while (u != v) {
      f[u] = w;
      u = fa[u];
      f[v] = w;
      v = fa[v];
    }
  }
  for (int i = 0; i != m; ++i) {
    int u = line[i].second.first, v = line[i].second.second, w = 1000000;
    while (d[u] > d[v]) {
      w = min(w, f[u]);
      u = fa[u];
    }
    while (u != v) {
      w = min(w, f[u]);
      u = fa[u];
      w = min(w, f[v]);
      v = fa[v];
    }
    if (w != line[i].first) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 2; i <= n; ++i) g[id[i]] = f[i];
  for (int i = 1; i != n; ++i) cout << g[i] << " \n"[i == n - 1];
}
