#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int mod = 1e9 + 7;
const int DEG = 30;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
static auto faster_iostream = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();
int n, ans[N], flag;
pair<int, int> fa[N][N];
vector<pair<int, int> > G[N];
void dfs(int x, int f, int r) {
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i].first;
    if (y == f) {
      continue;
    }
    fa[r][y] = make_pair(x, G[x][i].second);
    dfs(y, x, r);
  }
}
void solve(int a, int b, int c) {
  int now = b;
  while (now != a) {
    ans[fa[a][now].second] = max(ans[fa[a][now].second], c);
    now = fa[a][now].first;
  }
}
int getmi(int a, int b) {
  int res = 1e6;
  int now = b;
  while (now != a) {
    res = min(res, ans[fa[a][now].second]);
    now = fa[a][now].first;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back({y, i});
    G[y].push_back({x, i});
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, -1, i);
  }
  int m;
  cin >> m;
  vector<pair<int, pair<int, int> > > Q;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Q.push_back(make_pair(c, make_pair(a, b)));
  }
  for (int i = 0; i < m; i++) {
    solve(Q[i].second.first, Q[i].second.second, Q[i].first);
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 0) {
      ans[i] = 1e6;
    }
  }
  for (int i = 0; i < m; i++) {
    if (getmi(Q[i].second.first, Q[i].second.second) != Q[i].first) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << " \n"[i == n];
  }
  return 0;
}
