#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &out, const pair<T, V> x) {
  out << "{" << x.first << " : " << x.second << "}";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const set<T> x) {
  for (auto &it : x) {
    out << it << " ";
  }
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const multiset<T> x) {
  for (auto &it : x) {
    out << it << " ";
  }
  return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, const map<T, V> x) {
  for (auto &it : x) {
    out << "[" << it.first << "]"
        << " = " << it.second << "\n";
  }
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> x) {
  for (int i = 0; i < x.size() - 1; ++i) {
    out << x[i] << " ";
  }
  out << x.back();
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<vector<T> > x) {
  for (int i = 0; i < x.size() - 1; ++i) {
    out << "[" << i << "]"
        << " = {" << x[i] << "}\n";
  }
  out << "[" << x.size() - 1 << "]"
      << " = {" << x.back() << "}\n";
  return out;
}
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
vector<int> g[N];
vector<pair<long long, pair<long long, long long> > > ar;
int dp[N][32];
long long a[N];
int tin[N], tout[N], timer = 0;
void dfs(int v, int p) {
  tin[v] = timer++;
  dp[v][0] = p;
  for (int i = 1; i < 30; ++i) {
    dp[v][i] = dp[dp[v][i - 1]][i - 1];
  }
  for (auto &it : g[v]) {
    if (it == p) continue;
    dfs(it, v);
  }
  tout[v] = timer++;
}
bool cmp(int x, int y) { return tin[x] <= tin[y] && tout[y] <= tout[x]; }
int lca(int x, int y) {
  if (cmp(x, y)) return x;
  if (cmp(y, x)) return y;
  for (int i = 29; i >= 0; --i) {
    if (!cmp(dp[x][i], y)) x = dp[x][i];
  }
  return dp[x][0];
}
bool get(long long x, long long y, long long val) {
  while (x != y) {
    if (a[x] == 0 || a[x] == val) return true;
    x = dp[x][0];
  }
  return false;
}
void upd(long long x, long long y, long long val) {
  while (x != y) {
    if (a[x] == 0) a[x] = val;
    x = dp[x][0];
  }
}
vector<pair<long long, long long> > rd;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    rd.push_back({u, v});
  }
  dfs(1, 1);
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, mn;
    cin >> u >> v >> mn;
    ar.push_back({mn, {u, v}});
  }
  sort((ar).rbegin(), (ar).rend());
  for (auto &it : ar) {
    long long x = it.second.first, y = it.second.second;
    long long val = it.first;
    long long lc = lca(x, y);
    if (!get(x, lc, val) && !get(y, lc, val)) {
      cout << -1;
      return 0;
    }
    upd(y, lc, val);
    upd(x, lc, val);
  }
  for (auto &it : rd) {
    if (it.first == dp[it.second][0]) swap(it.first, it.second);
    if (a[it.first] == 0) a[it.first] = 1000000;
    cout << a[it.first] << " ";
  }
  return 0;
}
