#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long normalize(long long x, long long mod) {
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1e18 + 5;
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const long long N = 5005;
long long n, k, m, q, a, b;
long long mn[N], src, dest, val;
vector<pair<long long, long long> > g[N];
struct data {
  long long a, b, g;
};
data store[N];
bool dfs(long long u, long long par) {
  if (u == dest) return 1;
  for (auto &it : g[u]) {
    if (it.first == par) continue;
    if (dfs(it.first, u)) {
      mn[it.second] = max(mn[it.second], val);
      return 1;
    }
  }
  return 0;
}
bool dfs2(long long u, long long par, long long cur) {
  if (u == dest) return (cur == val);
  for (auto &it : g[u]) {
    if (it.first == par) continue;
    if (dfs2(it.first, u, min(cur, mn[it.second]))) return 1;
  }
  return 0;
}
void solve() {
  cin >> n;
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
    mn[i] = 1;
  }
  cin >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> store[i].a >> store[i].b >> store[i].g;
    src = store[i].a;
    dest = store[i].b;
    val = store[i].g;
    dfs(src, src);
  }
  for (long long i = 1; i <= m; i++) {
    src = store[i].a;
    dest = store[i].b;
    val = store[i].g;
    if (!dfs2(src, src, 1e9)) {
      cout << -1;
      return;
    }
  }
  for (long long i = 1; i <= n - 1; i++) cout << mn[i] << " ";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
