#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e3 + 10;
int n, m, edge[N];
vector<pair<int, int> > adj[N];
pair<int, pair<int, int> > query[N];
vector<int> path[N];
bool visited[N];
bool find_path(int u, int v, int id) {
  if (u == v) return true;
  visited[u] = true;
  for (auto it : adj[u])
    if (!visited[it.second]) {
      path[id].push_back(it.first);
      if (find_path(it.second, v, id)) return true;
      path[id].pop_back();
    }
  visited[u] = false;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(pair<int, int>(i, v));
    adj[v].push_back(pair<int, int>(i, u));
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    query[i] = pair<int, pair<int, int> >(w, pair<int, int>(u, v));
    memset(visited, false, sizeof(visited));
    find_path(u, v, i);
    for (auto it : path[i]) {
      edge[it] = max(edge[it], w);
    }
  }
  for (int i = 1; i <= m; i++) {
    int temp = INT_MAX;
    for (auto it : path[i]) temp = min(temp, edge[it]);
    if (temp != query[i].first) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (edge[i] == 0) edge[i] = 911218;
    cout << edge[i] << ' ';
  }
  return 0;
}
