Write a program which manipulates a weighted rooted tree $T$ with the following operations:

* $add(v,w)$: add $w$ to all edges from the root to node $u$

* $getSum(u)$: report the sum of weights of all edges from the root to node $u$



The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ to $n-1$ respectively where ID of the root is $0$. Note that all weights are initialized to zero.

Constraints

* All the inputs are given in integers
* $ 2 \leq n \leq 100000 $
* $ c_j < c_{j+1} $   $( 1 \leq j \leq k-1 )$
* $ 2 \leq q \leq 200000 $
* $ 1 \leq u,v \leq n-1 $
* $ 1 \leq w \leq 10000 $

Input

The input is given in the following format.

$n$
$node_0$
$node_1$
$node_2$
$:$
$node_{n-1}$
$q$
$query_1$
$query_2$
$:$
$query_{q}$


The first line of the input includes an integer $n$, the number of nodes in the tree.

In the next $n$ lines,the information of node $i$ is given in the following format:


ki c1 c2 ... ck


$k_i$ is the number of children of node $i$, and $c_1$ $c_2$ ... $c_{k_i}$ are node IDs of 1st, ... $k$th child of node $i$.

In the next line, the number of queries $q$ is given. In the next $q$ lines, $i$th query is given in the following format:


0 v w


or


1 u


The first integer represents the type of queries.'0' denotes $add(v, w)$ and '1' denotes $getSum(u)$.

Output

For each $getSum$ query, print the sum in a line.

Examples

Input

6
2 1 2
2 3 5
0
0
0
1 4
7
1 1
0 3 10
1 2
0 4 20
1 3
0 5 40
1 4


Output

0
0
40
150


Input

4
1 1
1 2
1 3
0
6
0 3 1000
0 2 1000
0 1 1000
1 1
1 2
1 3


Output

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

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

struct HLD {
  int n;
  vector<vector<int>>& g;
  vector<int> vid, head, sz, par;

  HLD(vector<vector<int>>& g): g(g), n(g.size()), vid(n,-1), head(n), sz(n,1), par(n) {}

  void dfs1(int v, int p) {
    if(g[v].size() && g[v][0] == p) swap(g[v][0],g[v].back());
    for(auto &to : g[v]) {
      if(to == p) continue;
      dfs1(to, v);
      sz[v] += sz[to];
      if(sz[to] > sz[g[v][0]]) swap(to,g[v][0]);
    }
  }

  void dfs2(int v, int p, int &k) {
    par[v] = p; vid[v] = k++;
    for(auto to : g[v]) {
      if(to == p) continue;
      head[to] = (to == g[v][0] ? head[v] : to);
      dfs2(to,v,k);
    }
  }

  void build(vector<int> rs = vector<int>(1,0)) {
    int k = 0;
    for(int r : rs) {
      dfs1(r,-1);
      head[r] = r;
      dfs2(r,-1,k);
    }
  }

  void for_each_vertex(int u, int v, const function<void(int,int)>& f) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      f(max(vid[head[v]],vid[u]),vid[v]);
      if(head[u] != head[v]) v = par[head[v]];
      else break;
    }
  }

  void for_each_edge(int u, int v, const function<void(int,int)>& f) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      if(head[u] != head[v]) {
        f(vid[head[v]],vid[v]); 
        v = par[head[v]];
      } else {
        if(u != v) f(vid[u]+1,vid[v]);
        break;
      }
    }
  }

  int lca(int u, int v) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      if(head[u] == head[v]) return u;
      v = par[head[v]];
    }
  }
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> tree(n);
  rep(i,n) {
    int k;
    cin >> k;
    int c;
    rep(j,k) {
      cin >> c;
      tree[i].push_back(c);
      tree[c].push_back(i);
    }
  }
  HLD hld(tree);
  hld.build();
  auto f = [](ll a, ll b){return a+b;};
  auto g = [](ll a, ll b, int l){return a+b*l;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(f)> lst(n,f,g,f,0,0);
  lst.build();
  int q;
  cin >> q;
  vector<ll> ans; 
  rep(i,q) {
    int type;
    cin >> type;
    if(type == 0) {
      ll v, w;
      cin >> v >> w;
      hld.for_each_edge(0,v,[&](int l, int r){lst.update(l,r+1,w);});
    } else {
      int v;
      cin >> v;
      ll val = 0;
      hld.for_each_edge(0,v,[&](int l, int r){val += lst.query(l,r+1);});
      ans.push_back(val);
    }
  }
  for(ll x : ans) cout << x << endl; 
}
