#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807;
const long long MOD = 1000000007;
long long power(long long a, long long b, long long z = MOD) {
  long long res = 1;
  a = (a % z);
  while (b) {
    if (b & 1) res = (res * a) % z;
    a = (a * a) % z;
    b = b >> 1;
  }
  return res;
}
long long inverse(long long a, long long z = MOD) { return power(a, z - 2, z); }
vector<int> aray[5001];
bool visit[5001];
int parent[5001][5001] = {0};
void dfs(int a, int i) {
  visit[a] = true;
  for (int j = 0; j < aray[a].size(); j++) {
    int num = aray[a][j];
    if (!visit[num]) {
      parent[i][num] = a;
      dfs(num, i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int> > path;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    path.push_back(make_pair(x, y));
    aray[x].push_back(y);
    aray[y].push_back(x);
  }
  int dist[n + 1][n + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      visit[j] = false;
      dist[i][j] = 1;
    }
    dfs(i, i);
  }
  int m;
  cin >> m;
  vector<pair<int, pair<int, int> > > v;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    v.push_back(make_pair(z, make_pair(x, y)));
  }
  sort(v.begin(), v.end());
  bool ans = true;
  for (int i = m - 1; i >= 0; i--) {
    int g = v[i].first, a = v[i].second.first, b = v[i].second.second;
    int curr = b, count = 0;
    while (curr != a) {
      int par = parent[a][curr];
      dist[par][curr] = max(dist[par][curr], g);
      dist[curr][par] = dist[par][curr];
      if (dist[curr][par] == g) count++;
      curr = par;
    }
    if (!count) {
      ans = false;
      break;
    }
  }
  if (!ans)
    cout << -1 << "\n";
  else {
    for (int i = 0; i < n - 1; i++) {
      int a = path[i].first, b = path[i].second;
      cout << dist[a][b] << " ";
    }
    cout << "\n";
  }
  return 0;
}
