#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
using pii = pair<long long, long long>;
template <class T>
void cmax(T& x, const T& y) {
  if (x < y) x = y;
}
template <class T>
void cmin(T& x, const T& y) {
  if (x > y) x = y;
}
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T>
void unique(vector<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void reverse(vector<T>& v) {
  reverse(v.begin(), v.end());
}
const long long SZ = 0x191981;
struct FILEIN {
  ~FILEIN() {}
  char qwq[SZ], *S = qwq, *T = qwq, ch;
  char GETC() {
    return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T)
               ? EOF
               : *S++;
  }
  FILEIN& operator>>(char& c) {
    while (isspace(c = GETC()))
      ;
    return *this;
  }
  FILEIN& operator>>(string& s) {
    while (isspace(ch = GETC()))
      ;
    s = ch;
    while (!isspace(ch = GETC())) s += ch;
    return *this;
  }
  template <class T>
  void read(T& x) {
    bool sign = 1;
    while ((ch = GETC()) < 0x30)
      if (ch == 0x2d) sign = 0;
    x = (ch ^ 0x30);
    while ((ch = GETC()) > 0x2f) x = x * 0xa + (ch ^ 0x30);
    x = sign ? x : -x;
  }
  FILEIN& operator>>(long long& x) { return read(x), *this; }
  FILEIN& operator>>(signed& x) { return read(x), *this; }
  FILEIN& operator>>(unsigned& x) { return read(x), *this; }
} in;
struct FILEOUT {
  const static long long LIMIT = 0x114514;
  char quq[SZ], ST[0x114];
  signed sz, O;
  ~FILEOUT() { sz = O = 0; }
  void flush() {
    fwrite(quq, 1, O, stdout);
    fflush(stdout);
    O = 0;
  }
  FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
  FILEOUT& operator<<(string str) {
    if (O > LIMIT) flush();
    for (char c : str) quq[O++] = c;
    return *this;
  }
  template <class T>
  void write(T x) {
    if (O > LIMIT) flush();
    if (x < 0) {
      quq[O++] = 0x2d;
      x = -x;
    }
    do {
      ST[++sz] = x % 0xa ^ 0x30;
      x /= 0xa;
    } while (x);
    while (sz) quq[O++] = ST[sz--];
    return;
  }
  FILEOUT& operator<<(long long x) { return write(x), *this; }
  FILEOUT& operator<<(signed x) { return write(x), *this; }
  FILEOUT& operator<<(unsigned x) { return write(x), *this; }
} out;
const long long maxn = 5e3 + 5;
long long n, m;
long long ac[maxn];
long long bc[maxn];
long long gc[maxn];
long long val[maxn];
long long ans = 0;
struct node {
  long long v, id;
};
vector<node> g[maxn];
long long tmpb = 0, tmpg = 0;
bool dfs(long long u, long long fa) {
  if (u == tmpb) return 1;
  bool tmp = 0;
  for (node v : g[u]) {
    long long to = v.v;
    if (to ^ fa) {
      if (dfs(to, u)) {
        tmp = 1;
        cmax(val[v.id], tmpg);
      }
    }
  }
  return tmp;
}
bool qry(long long u, long long fa) {
  if (u == tmpb) return 1;
  bool tmp = 0;
  for (node v : g[u]) {
    long long to = v.v;
    if (to ^ fa) {
      if (qry(to, u)) {
        tmp = 1;
        cmin(ans, val[v.id]);
      }
    }
  }
  return tmp;
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  in >> n;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    in >> u >> v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  in >> m;
  for (long long i = 1; i <= m; i++) {
    long long a, b, g;
    in >> a >> b >> g;
    ac[i] = a;
    bc[i] = b;
    tmpb = b;
    gc[i] = g;
    tmpg = g;
    dfs(a, 0);
  }
  for (long long i = 1; i <= m; i++) {
    long long a = ac[i];
    long long b = bc[i];
    tmpb = b;
    long long g = gc[i];
    ans = 1e9;
    qry(a, 0);
    if (ans != g) {
      out << -1 << '\n';
      return out.flush(), 0;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (!val[i])
      out << 1000000 << ' ';
    else {
      out << val[i] << ' ';
    }
  }
  return out.flush(), 0;
}
