#include <bits/stdc++.h>

using namespace std;

#define rep(i,n)      for(long long(i)=0;(i)<(n);(i)++)

void dfs_root(vector<vector<long long>>& Graph, vector<long long>&root, vector<bool>&seen, long long cur){
    for(auto it : Graph[cur]){
        if(!seen[it]){
            seen[it] = true;
            root[it] = cur;
            dfs_root(Graph, root, seen, it);
        }
    }
}


void dfs_add(vector<vector<long long>>& Graph, vector<long long>&root, vector<bool>&seen, vector<long long> &add,long long cur, long long s){

    // current の addを処理
    seen[cur] = true;
    root[cur] = add[cur] + s;

    for(auto it : Graph[cur]){
        if(!seen[it]){
            dfs_add(Graph, root, seen, add, it, s + add[cur]);
        }
    }
}

int main(){

    long long n;
    cin >> n;

    vector<long long> a(n),b(n);
    vector<vector<long long>> Graph(n);
    rep(i,n - 1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        Graph[a[i]].push_back(b[i]);
        Graph[b[i]].push_back(a[i]);
    }

    long long q;
    cin >> q;

    vector<long long> root(n, -1);
    vector<bool>      seen(n, false);
    seen[0] = true;
    dfs_root(Graph, root, seen, 0);

    vector<long long> add(n,0);
    rep(i,q){
        long long t,e,x;
        cin >> t >> e >> x;

        long long A,B;
        A = a[e - 1];
        B = b[e - 1];

        if(t == 2)
            swap(A,B);

        if(root[A] == B){
            add[A] += x;
        } else {
            add[0] += x;
            add[B] -= x;
        }
    }

    rep(i,n) root[i] = 0;
    rep(i,n) seen[i] = false;

    seen[0] = true;
    dfs_add(Graph, root, seen , add, 0, 0);

    rep(i,n){
        cout << root[i] << endl;
    }

    return 0;
}
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define pp pair<ll,ll>
#define ll int
#define True 1
#define gcd __gcd
#define range(i,a,b,c) for(ll i=a;i<b;i+=c)
#define int long long
#define lb lower_bound
#define ub upper_bound
#define False 0
#define maxa(p,q) *max_element(p,q)
#define mina(p,q) *min_element(p,q)
#define pq priority_queue<int>
#define all(v) v.begin(),v.end()
#define len(p) p.size()
#define append pb
#define foi(p,n) for(int i=p;i<n;i++)
#define ini(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define fi first
#define swap(i,j) {int temp=i,i=j,j=temp;}
#define sec second
#define mp make_pair
#define tc while(t--)
#define N ((ll)1001)
#define gtc(a,b) cout<<"Case #"<<a<<": "<<b<<endl;
#define va(n) vector<ar<ll,n>>
#define fo(n) for(int i=0;i<n;i++)
#define rev(n) for(int i=n-1;i>=0;i--)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define ar array
#define vp vector<pair<int,int>>
#define vc vector<int>
#define print(p) cout<<p<<"\n";
#define pr(p) cout<<p<<" ";
#define pr2(p,q) cout<<p<<" "<<q<<endl;
#define pr3(p,q,r) cout<<p<<" "<<q<<" "<<r<<endl;
#define pr4(p,q,r,s) cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;
#define pra(a) for(ll i: a) cout<<i<<" "; cout<<endl;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define isvalid(i,j) (0<=i and i<n and 0<=j and j<m)
#define gh fflush(stdout)
#define why {print("LOL") return 0;}
using namespace std;


ll n,m,t,k,r,maxn,x,y,flag=0,l1,r1,l2,r2,parity[2]={0,0},ok,q,need,p;
ll mod=1e9+7;


signed main()
{
fio
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); 
	freopen("all.txt", "w", stdout);
#endif

t=1;
//cin>>t;
ll uu=t;

tc{
	cin>>n>>m;
	va(3) a[n+1];
	multiset<ar<ll,2>> s;
	fo(m) {
		ll x,y,c,d;
		cin>>x>>y>>c>>d;
		a[x].pb({y,c,d});
		a[y].pb({x,c,d});
	}
	ll dis[n+1];
	fo(n+1) dis[i]=-1;
	dis[1]=0;
	s.insert({0,1});
	while(s.size()){
		auto i=*s.begin();
		s.erase(s.begin());
		for(auto j: a[i[1]]){
			for(ll k=max(i[0],(ll)sqrt(j[2])-5);k<=max(i[0],(ll)sqrt(j[2])+5);k++)
			if(k>=i[0] and (dis[j[0]]==-1 or dis[j[0]]>k+j[1]+j[2]/(k+1))){
				if(s.find({dis[j[0]],j[0]})!=s.end())
					s.erase(s.find({dis[j[0]],j[0]}));
				dis[j[0]]=k+j[1]+j[2]/(k+1);
				s.insert({dis[j[0]],j[0]});
			}
		}
	}
	print(dis[n])
}

return 0;}
