#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int n, m, T;
int a[maxn];
vector<pair<int, int> > g[maxn];
int dep[maxn];
int f[maxn];
pair<int, int> val[maxn];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[u] = fa;
  for (auto to : g[u]) {
    if (to.first == fa) continue;
    dfs(to.first, u);
    val[to.first] = {mod, to.second};
  }
}
struct node {
  int s, t, w;
  bool operator<(const node b) const { return w > b.w; }
} q[maxn];
bool gao(int x, int y, int w) {
  if (dep[x] < dep[y]) swap(x, y);
  int mi = mod;
  while (dep[x] > dep[y]) {
    if (val[x].first == mod) {
      val[x].first = w;
    }
    mi = min(val[x].first, mi);
    x = f[x];
  }
  while (x != y) {
    if (val[x].first == mod) {
      val[x].first = w;
    }
    if (val[y].first == mod) {
      val[y].first = w;
    }
    mi = min(val[x].first, mi);
    mi = min(val[y].first, mi);
    x = f[x];
    y = f[y];
  }
  return mi == w;
}
int ans[maxn];
int main() {
  cin >> n;
  for (int i = 1, uu, vv; i <= n - 1; i++) {
    cin >> uu >> vv;
    g[uu].push_back({vv, i});
    g[vv].push_back({uu, i});
  }
  dfs(1, 0);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> q[i].s >> q[i].t >> q[i].w;
  }
  sort(q + 1, q + 1 + m);
  for (int i = 1; i <= m; i++) {
    if (!gao(q[i].s, q[i].t, q[i].w)) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans[val[i].second] = val[i].first;
  }
  for (int i = 1; i <= n - 1; i++) {
    if (ans[i] == mod) ans[i] = 1e6;
    cout << ans[i] << " ";
  }
  return 0;
}
