#include <bits/stdc++.h>
using namespace std;
const int sz = 5e3 + 9;
int n, m;
vector<pair<int, int>> v[sz];
int a, b, g;
int ans[sz];
int first, t;
set<pair<int, pair<int, int>>> mys;
int dfs1(int idx, int to, int val, int par = -1) {
  if (idx == to) return 1;
  int ret = 0;
  for (auto u : v[idx]) {
    int nxt = u.first;
    int i = u.second;
    if (nxt == par) continue;
    int tmp = dfs1(nxt, to, val, idx);
    if (tmp) ans[i] = val;
    ret |= tmp;
  }
  return ret;
}
int dfs2(int idx, int to, int par = -1) {
  if (idx == to) return -1;
  int ret = 1e9;
  for (auto u : v[idx]) {
    int nxt = u.first;
    int i = u.second;
    if (nxt == par) continue;
    int tmp = dfs2(nxt, to, idx);
    if (tmp != 1e9) {
      if (~tmp)
        ret = min(ret, min(tmp, ans[i]));
      else
        ret = min(ret, ans[i]);
    }
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d %d", &first, &t);
    v[first].push_back(make_pair(t, i));
    v[t].push_back(make_pair(first, i));
    ans[i] = 1e9;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &g);
    mys.insert(make_pair(g, make_pair(a, b)));
  }
  for (auto u : mys) {
    g = u.first;
    a = u.second.first;
    b = u.second.second;
    dfs1(a, b, g);
  }
  for (auto u : mys) {
    g = u.first;
    a = u.second.first;
    b = u.second.second;
    int tmp = dfs2(a, b);
    if (tmp != g) {
      puts("-1");
      return 0;
    }
  }
  int mx = 1e6;
  for (int i = 1; i <= n - 1; i++) printf("%d ", min(ans[i], mx));
  return 0;
}
