#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
//Do DEBUG OR NOT
#define DEBUG

#ifdef DEBUG
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#else 
#define debug(...) true
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

//prototype declaration
ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m
ll gcd(ll a, ll b);//最大公約数 2引数
ll ngcd(vector<ll> a);
ll lcm(ll a, ll b);//最小公倍数 2引数
ll nlcm(vector<ll> numbers);
bool isPrime(ll x);//素数判定
ll digsum(ll n);//桁和
vector<ll> enum_div(ll n);//約数全列挙
ll stringcount(string s, char c);//特定文字カウント

ll pow_ten(ll n){
    ll x=1;
    for(ll i=0;i<n;i++){
        x*=10;
    }
    return x;
}

//__________________________main__________________________

int main(){
    ll N;
    cin>>N;
    ll i=0;
    ll times=1000;
    for(i=0;i<5;i++){
        if(N/times==0) break;
        times*=1000;
    }
    //debug(i);
    ll ans=0;
    if(i>0){
        for(ll j=1;j<i;j++){
            ans+=(pow_ten((j+1)*3)-pow_ten(j*3))*j;
            //debug(ans);
        }
        ans+=(N-pow_ten(i*3)+1)*i;
    }
    //debug(pow_ten(10));
    cout<<ans<<endl;
    


    return 0;
}


//__________________________functions_____________Ctrl+K,Ctrl+0
//繰り返し二乗法関数
ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m
    ll r=1;
    for(;k>0;k=k>>1){
        if(k&1) r=(r*n)%m;
        n = (n*n) % m;
    }
    return r;
}
//最大公約数 2引数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最大公約数 n引数
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
//最小公倍数 2引数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
//最小公倍数 n引数
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}
//桁和
ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
//約数全列挙
vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
//特定文字カウント
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n;
vector<int> a, b;
vector<vector<int>> e;
vector<int> depth;
vector<ll> ans;

void dfs_depth(int v, int d) {
  depth[v] = d;
  for (auto nv : e[v]) {
    if (depth[nv] != -1) continue;
    dfs_depth(nv, d + 1);
  }
}

void dfs_ans(int v, ll tot) {
  tot += ans[v];
  ans[v] = tot;
  for (auto nv : e[v]) {
    if (depth[v] > depth[nv]) continue;
    dfs_ans(nv, tot);
  }
}

int main() {
  cin >> n;

  a.resize(n - 1);
  b.resize(n - 1);
  e.resize(n);
  rep(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;

    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }

  depth.assign(n, -1);
  dfs_depth(0, 0);

  ans.resize(n);

  int q;
  cin >> q;
  rep(i, q) {
    int t, e, x;
    cin >> t >> e >> x;
    e--;
    
    int ok, ng;
    if (t == 1) {
      //b[e]を通らない
      ok = a[e];
      ng = b[e];
    }
    else {
      //a[e]を通らない
      ok = b[e];
      ng = a[e];
    }

    if (depth[ok] < depth[ng]) {
      //根に足す
      ans[0] += x;
      ans[ng] -= x;
    }
    else {
      //部分木に足す
      ans[ok] += x;
    }
  }

  dfs_ans(0, 0);
  rep(i, n) cout << ans[i] << endl;
  return 0;
}