#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

int main(){
  int n, q, t, e, x, l, r;
  cin >> n;
  vector<vector<int>> g(n);
  int a[n-1], b[n-1];
  rep(i,n-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]);
  }
  vector<ll> par(n), val(n);
  par[0] = -1;
  auto dfs1 = [&](auto self, int v, int p) -> void {
    for(auto x : g[v]) {
      if(x == p) continue;
      par[x] = v;
      self(self,x,v);
    }
  };
  dfs1(dfs1,0,-1);
  cin >> q;
  rep(i,q) {
    cin >> t >> e >> x;
    e--;
    l = a[e], r = b[e];
    if(t == 2) swap(l,r);
    if(par[l] == r) val[l] += x;
    else val[0] += x, val[r] -= x;
  }
  auto dfs2 = [&](auto self, int v, int p) -> void {
    for(auto x : g[v]) {
      if(x == p) continue;
      val[x] += val[v];
      self(self,x,v);
    }
  };
  dfs2(dfs2,0,-1);
  rep(i,n) cout << val[i] << endl;
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define ll long long

priority_queue < pair < ll, int > > q;

int n, m, tot, hd[100005], vis[100005], to[200005], nxt[200005], c[200005], d[200005];

ll dis[100005];

int read()
{
	int x = 0, fl = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + ch - '0'; ch = getchar();}
	return x * fl;
}

void add(int x, int y, int c0, int d0)
{
	tot ++ ;
	to[tot] = y;
	nxt[tot] = hd[x];
	c[tot] = c0;
	d[tot] = d0;
	hd[x] = tot;
	return;
}

ll s(ll x, ll y)
{
	if (x <= 0) return 1e18;
	return x + y / x;
}

void Dij()
{
	for (int i = 2; i <= n; i ++ )
		dis[i] = 1e18;
	q.push(make_pair(0, 1));
	while (!q.empty())
	{
		pair < int, int > h = q.top(); q.pop();
		int x = h.second; 
		if (vis[x]) continue; vis[x] = 1;
		for (int i = hd[x]; i; i = nxt[i])
		{
			int y = to[i], c0 = c[i], d0 = d[i], p0, p = (int)(sqrt(d0));
			ll r1 = s(p - 1, d0), r2 = s(p, d0), r3 = s(p + 1, d0), z, tmp;
			if (r1 <= r2 && r1 <= r3) p0 = p - 1; else if (r2 <= r1 && r2 <= r3) p0 = p; else p0 = p + 1;
//			printf("%lld %lld %lld %d %d\n", r1, r2, r3, p, p0);
			if (dis[x] < p0 - 1) tmp = (ll)(s(p0, d0) + c0 - 1); else tmp = (ll)(s(dis[x] + 1, d0) + c0 - 1);
//			printf("%d %d %lld\n", x, y, tmp);
			if (dis[y] > tmp)
			{
				dis[y] = tmp;
				q.push(make_pair(-dis[y], y));
			}
		}
	}
	return;
}

int main()
{
	n = read(); m = read();
	for (int i = 1; i <= m; i ++ )
	{
		int x = read(), y = read(), c0 = read(), d0 = read();
		add(x, y, c0, d0), add(y, x, c0, d0);
	}
	Dij();
	printf("%lld\n", dis[n] == 1e18 ? -1 : dis[n]);
	return 0;
}