#include <bits/stdc++.h>
using namespace std;
struct P {
  int v, id;
};
struct PP {
  int a, b, c;
};
const int MAXN = 50 * 100;
vector<P> adj[MAXN];
int vm[MAXN];
P parent[MAXN];
int inter[MAXN][2];
int in = 0;
void parcours(int noeud, int pere, int id) {
  parent[noeud] = {pere, id};
  inter[noeud][0] = in;
  in++;
  for (auto voisin : adj[noeud]) {
    if (voisin.v != pere) {
      parcours(voisin.v, noeud, voisin.id);
    }
  }
  inter[noeud][1] = in;
  in++;
}
bool ancetre(int a, int b) {
  if (inter[a][0] <= inter[b][0] && inter[a][1] >= inter[b][1]) return true;
  return false;
}
void remplir(int actu, int check, int valeur) {
  if (parent[actu].v == -1 || ancetre(actu, check)) {
    return;
  }
  vm[parent[actu].id] = max(vm[parent[actu].id], valeur);
  remplir(parent[actu].v, check, valeur);
}
int minSur(int actu, int check) {
  if (parent[actu].v == -1 || ancetre(actu, check)) {
    return 1e6;
  }
  return min(vm[parent[actu].id], minSur(parent[actu].v, check));
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back({b, i});
    adj[b].push_back({a, i});
  }
  parcours(0, -1, -1);
  int nbQuestions;
  cin >> nbQuestions;
  vector<PP> questions;
  for (int i = 0; i < nbQuestions; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    questions.push_back({a, b, c});
    remplir(a, b, c);
    remplir(b, a, c);
  }
  for (int i = 0; i < N; i++)
    if (vm[i] == 0) vm[i] = 1e6;
  for (int i = 0; i < nbQuestions; i++) {
    int leMin = min(minSur(questions[i].b, questions[i].a),
                    minSur(questions[i].a, questions[i].b));
    if (leMin != questions[i].c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << vm[i] << " ";
  }
  cout << endl;
}
