#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
int add(int x, int y) { return x + y > 998244353 ? x + y - 998244353 : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
vector<pair<int, int> > G[5005];
int fa[5005], fe[5005], n, val[5005];
struct Node {
  int u, v, w;
};
Node a[5005];
bool cmp(Node x, Node y) { return x.w > y.w; }
void dfs(int u, int Fa) {
  fa[u] = Fa;
  for (pair<int, int> v : G[u]) {
    if (v.first == Fa) continue;
    fe[v.first] = v.second;
    dfs(v.first, u);
  }
}
signed main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G[u].push_back(make_pair(v, i)), G[v].push_back(make_pair(u, i));
  }
  int m = read();
  for (int i = 1; i <= m; i++) {
    a[i].u = read(), a[i].v = read(), a[i].w = read();
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    dfs(a[i].u, 0);
    bool ok = 0;
    int tmp = a[i].v;
    while (tmp != a[i].u) {
      int e = fe[tmp];
      if (val[e] <= a[i].w) ok = 1, val[e] = a[i].w;
      tmp = fa[tmp];
    }
    if (ok == 0) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 1; i < n; i++) printf("%d ", max(val[i], 1));
  cout << "\n";
  return 0;
}
