#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct edge {
  int u, v, i;
  int nxt;
} e[maxn];
struct AK {
  int u, v, w;
  bool operator<(const AK& a) const { return w > a.w; }
} ak[maxn];
int cnt;
int head[maxn];
void add_edge(int u, int v, int pos) {
  e[cnt].u = u, e[cnt].v = v, e[cnt].i = pos;
  e[cnt].nxt = head[u];
  head[u] = cnt++;
}
int val[maxn];
vector<int> vec[maxn];
bool dfs(int u, int fa, int id) {
  if (u == ak[id].v) return true;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    int ee = e[i].i;
    if (dfs(v, u, id)) {
      val[ee] = max(val[ee], ak[id].w);
      vec[id].push_back(ee);
      return true;
    }
  }
  return false;
}
int main() {
  int n;
  memset(val, 0, sizeof val);
  memset(head, -1, sizeof head);
  cnt = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v, i);
    add_edge(v, u, i);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &ak[i].u, &ak[i].v, &ak[i].w);
  }
  sort(ak, ak + m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    a = ak[i].u, b = ak[i].v;
    dfs(a, -1, i);
  }
  const int INF = 0x3f3f3f3f;
  for (int i = 0; i < m; i++) {
    int minv = INF;
    for (int j : vec[i]) {
      if (val[j] < minv) {
        minv = val[j];
      }
    }
    if (minv != ak[i].w) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (i != 1) cout << " ";
    if (val[i] == 0)
      cout << 1;
    else
      cout << val[i];
  }
}
