#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

vector< int > ans;

void opt( int );

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	ll n;
	vector< ll > a, b;
	{
		ll x = 1, y = 1;
		a.push_back( x );
		a.push_back( y );
		while( true ) {
			x += y;
			if( x > 1e18 )
				break;
			a.push_back( x );
			swap( x, y );
		}
	}
	cin >> n;
	while( a[ a.size() - 1 ] > n )
		a.pop_back();
	for( auto v: a )
		b.push_back( v );
	while( true ) {
		int i = b.size() - 1;
		if( b[ i ] == n )
			break;
		ll del = n - b[ i ];
		int j = 0;
		while( j + 1 < a.size() && a[ j + 1 ] <= del )
			++j;
		int fk = i - j;
		for( int k = b.size() - 1; k >= fk; --k )
			b[ k ] += a[ k - fk ];
	}
	ll x = 0, y = 0;
	for( int i = 0, j = b.size() & 1; i < b.size(); ++i, j = 1 - j ) {
		if( j ) {
			x += y;
			assert( x == b[ i ] || x + 1 == b[ i ] );
			opt( 3 );
			if( x != b[ i ] ) {
				++x;
				opt( 1 );
			}
		} else {
			y += x;
			assert( y == b[ i ] || y + 1 == b[ i ] );
			opt( 4 );
			if( y != b[ i ] ) {
				++y;
				opt( 2 );
			}
		}
	}
	assert( x == n );
	cout << ans.size() << '\n';
	for( auto v: ans )
		cout << v << '\n';
	return 0;
}

void opt( int x ) {
	ans.push_back( x );
	assert( ans.size() <= 130 );
}
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=asin(1)*2;
//using namespace atcoder;

vector<vector<ll>> G(200010);
map<Pll,ll> mp;
map<Pll,ll> np;
vector<ll> ans(200010,0);

ll dfs(ll v, ll p){
    //sum += mp[Pll(p,v)];
    //ans[v] += sum;
    ll ret = 0;
    for(auto& u:G[v]){
        if(u==p)continue;
        ret += dfs(u,v);
    }
    return np[{v,p}] = ret + mp[{v,p}];
    //mp[Pll(-1,v)] += sum;
}
void bfs(ll v, ll p){
    ll ret = 0;
    for(auto& u:G[v]){
        ret += np[{u,v}];
    }
    ans[v] = ret;
    for(auto& u:G[v]){
        if(u == p) continue;
        np[{v,u}] = ans[v] - np[{u,v}] + mp[{v,u}]; 
        bfs(u,v);
    }
}

int main(){
    ll N;
    cin >> N;
    vector<ll> 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]);
    }
    ll Q;
    cin >> Q;
    vector<ll> T(Q), E(Q), X(Q);
    rep(i,Q){
        cin >> T[i] >> E[i] >> X[i];
        E[i]--;
    }
    rep(i,Q){
        ll e = E[i];
        if(T[i] == 1){
            mp[Pll(B[e], A[e])] += X[i];
        }else{
            mp[Pll(A[e], B[e])] += X[i];
        }
    }
    dfs(0,-1);
    //for(auto&e:mp){
    //    cout << e.fi.fi << " " << e.fi.se << "   " << e.se << endl;
    //}
    bfs(0,-1);
    rep(i,N){
        cout << ans[i] << endl;
    }
}