#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, 1, -1, 1, -1, -1, 0};
int dy[] = {0, 1, 1, -1, -1, 1, 0, -1};
vector<pair<int, int>> G[5001];
vector<int> ans(5001, -1);
bool f = true;
bool dfs(int u, int v, int t, int x) {
  if (u == t) {
    return true;
  }
  for (auto g : G[u]) {
    if (g.first == v) continue;
    if (dfs(g.first, u, t, x)) {
      if (ans[g.second] == -1 || ans[g.second] == x) {
        ans[g.second] = x;
        f = false;
      }
      return true;
    }
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    G[a].push_back(make_pair(b, i));
    G[b].push_back(make_pair(a, i));
  }
  int m;
  cin >> m;
  vector<pair<int, pair<int, int>>> v(m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &v[i].second.first, &v[i].second.second, &v[i].first);
    v[i].second.first--, v[i].second.second--;
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < m; i++) {
    f = true;
    dfs(v[i].second.first, v[i].second.first, v[i].second.second, v[i].first);
    if (f) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1)
      printf("1000000");
    else
      printf("%d", ans[i]);
    cout << (i + 1 == n ? "\n" : " ");
  }
  return 0;
}
