#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 5003;
int n, m;
int f[N];
vector<pair<int, int> > a[N];
vector<int> path[N];
struct x {
  int u, v, mi;
} ask[N];
bool dfs(int fa, int rt, int fy, int col, int i) {
  if (rt == fy) return 1;
  for (auto s : a[rt]) {
    int t = s.first;
    if (fa == t) continue;
    if (dfs(rt, t, fy, col, i)) {
      path[i].push_back(s.second);
      f[s.second] = max(f[s.second], col);
      return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(f, -1, sizeof(f));
  for (int i = (1); i <= (n - 1); i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(make_pair(y, i));
    a[y].push_back(make_pair(x, i));
  }
  cin >> m;
  for (int i = (1); i <= (m); i++) {
    cin >> ask[i].u >> ask[i].v >> ask[i].mi;
    dfs(0, ask[i].u, ask[i].v, ask[i].mi, i);
  }
  for (int i = (1); i <= (m); i++) {
    int minn = 1e9;
    for (auto t : path[i]) minn = min(minn, f[t]);
    if (minn != ask[i].mi) {
      cout << -1;
      return 0;
    }
  }
  for (int i = (1); i <= (n - 1); i++) cout << max(f[i], 1) << " ";
  return 0;
}
