#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll INF = 1e18+10;
const ll mod = 1e9+9;
const ll MAXN = 2e5+10;

ll poww(ll a, ll b) {    
    if(b<0) return 0LL;
    ll ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        a = a * a;
        b >>= 1;
    }   
    return ans;
}
ll binpow(ll a, ll b, ll m) 
{
    if (b < 0) return 0LL;
    if (a <= 0)return 0LL;
    a %= m;
    
    ll ans = 1LL;
    while (b) {
        if (b & 1)ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}
ll modinv(ll n) {
    return binpow(n, mod - 2, mod);
}

void solve() {
    ll a,b,c; cin>>a>>b>>c;
    ll x = a%10,og=a%10;
    set<ll> st; vector<ll> v;
    st.insert(x); v.pb(x); x*=x; x%=10;
    while(st.find(x)==st.end()) {
        st.insert(x); v.pb(x); x*=og; x%=10;
    }
    ll sz = st.size();
    ll r = binpow(b,c,sz); r = (r-1+sz)%sz;
    cout<<v[r];
}

int main() {
    IOS; 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    //ll no_of_test_cases; cin>>no_of_test_cases; 
    ll no_of_test_cases = 1;
    //cout<<setprecision(10);
    
    for(ll i=1; i<=no_of_test_cases; i++) {
        solve();
    } 
    return 0; 
}


#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
ll n;
map<ll,ll> que[LIMIT1];
ll all_add=0;
vector<ll> edge[LIMIT1];
ll res[LIMIT1]={0};
vector<bool> visited(LIMIT1,false);
void dfs(ll i,ll parent,ll addd){
  visited[i] = true;
  
  res[i] += addd;
  for(auto p : edge[i]){
    if(!visited[p]){
      if(que[p].count(i)){
        addd += que[p][i];
      }
      if(que[i].count(p)){
        addd -= que[i][p];
        all_add += que[i][p];
      }
      dfs(p,i,addd);
      if(que[p].count(i)){
        addd -= que[p][i];
      }
      if(que[i].count(p)){
        addd += que[i][p];
      }
    }
  }
}
int main(void){
  initialize();
  ll m,i,j,k,result=0,q,t,e,x;
  int a[LIMIT2]={0},b[LIMIT1]={};
  string s;
  queue<ll> path;
  
  cin >> n;
  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);
  }
  cin >> q;
  rep(i,q){
    cin >> t >> e >> x;
    e--;
    if(t==1){
      que[a[e]][b[e]] += x;
    }else{
      que[b[e]][a[e]] += x;
    }
  }

  dfs(0,-1,0);
  
  rep(i,n){
    res[i] += all_add;
    cout << res[i] << '\n';
  }
  return 0;
}
