#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  bool first = true;
  for (const auto& j : v) {
    if (!first) {
      os << " ";
    }
    first = false;
    os << j;
  }
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& elem : v) {
    is >> elem;
  }
  return is;
}
vector<vector<int> > g;
vector<int> p;
vector<int> h;
void dfs(int x, int prev) {
  p[x] = prev;
  h[x] = (prev == -1) ? 0 : h[prev] + 1;
  for (int y : g[x]) {
    if (y != prev) {
      dfs(y, x);
    }
  }
}
struct v {
  int a;
  int b;
  int c;
};
bool comp(const v& x, const v& y) { return x.c < y.c; }
void solve() {
  int n;
  cin >> n;
  g.resize(n + 1);
  h.assign(n + 1, -1);
  p.assign(n + 1, -1);
  vector<pair<int, int> > qq;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    qq.push_back(pair<int, int>(x, y));
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, -1);
  int m;
  cin >> m;
  vector<v> q(m);
  for (int i = 0; i < m; i++) {
    cin >> q[i].a >> q[i].b >> q[i].c;
  }
  sort(q.begin(), q.end(), comp);
  vector<int> ans(n + 1, 1);
  for (int i = 0; i < m; i++) {
    int x = q[i].a;
    int y = q[i].b;
    int c = q[i].c;
    while (h[x] < h[y]) {
      ans[y] = c;
      y = p[y];
    }
    while (h[x] > h[y]) {
      ans[x] = c;
      x = p[x];
    }
    while (x != y) {
      ans[y] = c;
      ans[x] = c;
      y = p[y];
      x = p[x];
    }
  }
  for (int i = 0; i < m; i++) {
    int x = q[i].a;
    int y = q[i].b;
    int c = q[i].c;
    int mi = (h[x] < h[y]) ? ans[y] : ans[x];
    while (h[x] < h[y]) {
      mi = min(mi, ans[y]);
      y = p[y];
    }
    while (h[x] > h[y]) {
      mi = min(mi, ans[x]);
      x = p[x];
    }
    while (x != y) {
      mi = min(mi, ans[x]);
      mi = min(mi, ans[y]);
      y = p[y];
      x = p[x];
    }
    if (mi != c) {
      cout << -1;
      return;
    }
  }
  for (auto ww : qq) {
    if (h[ww.first] > h[ww.second]) {
      cout << ans[ww.first] << ' ';
    } else {
      cout << ans[ww.second] << ' ';
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  if (0) {
    int tests;
    cin >> tests;
    while (tests--) {
      solve();
      cout << "\n";
    }
  } else {
    solve();
    cout << endl;
  }
  return 0;
}
