#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %
         1000000007LL;
}
struct Node {
  long long u, v, w;
};
bool compare(Node A, Node B) { return A.w > B.w; }
int sectionInd[5001][5001];
vector<long long> path;
bool dfs(long long i, long long v, long long p, vector<long long> adj[]) {
  if (i == v) {
    return true;
  }
  bool ret = false;
  for (auto it : adj[i]) {
    if (it == p) {
      continue;
    }
    ret = dfs(it, v, i, adj);
    if (ret) {
      path.push_back(it);
      return true;
    }
  }
  return ret;
}
void Flash() {
  long long n;
  cin >> n;
  vector<long long> adj[n];
  long long u, v, minBeauty, ind;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v), adj[v].push_back(u);
    sectionInd[u][v] = i;
    sectionInd[v][u] = i;
  }
  long long ans[n - 1];
  for (long long i = 0; i < n - 1; i++) {
    ans[i] = 1000000LL;
  }
  long long m;
  cin >> m;
  bool chk = false;
  Node queries[m];
  for (long long i = 0; i < m; i++) {
    cin >> u >> v >> minBeauty;
    --u, --v;
    queries[i].u = u, queries[i].v = v, queries[i].w = minBeauty;
  }
  sort(queries, queries + m, compare);
  for (long long i = 0; i < m; i++) {
    u = queries[i].u, v = queries[i].v, minBeauty = queries[i].w;
    path.clear();
    dfs(u, v, u, adj);
    path.push_back(u);
    chk = false;
    for (long long i = 0; i < path.size() - 1; i++) {
      ind = sectionInd[path[i]][path[i + 1]];
      if (ans[ind] == 1000000LL || ans[ind] == minBeauty) {
        chk = true;
        ans[ind] = minBeauty;
      }
    }
    if (!chk) {
      cout << "-1\n";
      return;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
