Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))



// https://kopricky.github.io/code/DataStructure_OnGraph/link_cut_tree.html
// 以下の実装では link, range, query などで reroot が起こる
template<typename T> class LinkCutTree {
public:
	struct node {
		int sz;
		T val, al, lazy;
		node *left, *right, *par;
		bool rev;
		node() : sz(1), val(id2), al(id2), lazy(id1),
			left(nullptr), right(nullptr), par(nullptr), rev(false){}
		node(T _val) : sz(1), val(_val), al(_val), lazy(id1),
			left(nullptr), right(nullptr), par(nullptr), rev(false){}
		inline bool isRoot() const {
			return (!par) || (par->left != this && par->right != this);
		}
		void push(){
			if(lazy != id1){
				opr1(val, lazy), al += lazy * sz;
				if(left) opr1(left->lazy, lazy);
				if(right) opr1(right->lazy, lazy);
				lazy = id1;
			}
			if(!rev) return;
			swap(left, right);
			if(left) left->rev = !(left->rev);
			if(right) right->rev = !(right->rev);
			rev = false;
		}
		void eval(){
			sz = 1, al = val;
			if(left) left->push(), sz += left->sz, al = (rev ? opr2(al, left->al) : opr2(left->al, al));
			if(right) right->push(), sz += right->sz, al = (rev ? opr2(right->al, al) : opr2(al, right->al));
		}
	};
	static const T id1 = (T)0;
	static const T id2 = (T)0;
	inline static void opr1(T& arg1, const T arg2){
		arg1 += arg2;
	}
	inline static T opr2(const T arg1, const T arg2){
		return arg1 + arg2;
	}
 
private:
	// 回転
	void rotate(node* u, bool right){
		node *p = u->par, *g = p->par;
		if(right){
			if((p->left = u->right)) u->right->par = p;
			u->right = p, p->par = u;
		}else{
			if((p->right = u->left)) u->left->par = p;
			u->left = p, p->par = u;
		}
		p->eval(), u->eval(), u->par = g;
		if(!g) return;
		if(g->left == p) g->left = u;
		if(g->right == p) g->right = u;
		g->eval();
	}
	// u を splay 木の根にする
	void splay(node* u){
		while(!(u->isRoot())){
			node *p = u->par, *gp = p->par;
			if(p->isRoot()){ // zig
				p->push(), u->push();
				rotate(u, (u == p->left));
			}else{
				gp->push(), p->push(), u->push();
				bool flag = (u == p->left);
				if((u == p->left) == (p == gp->left)){ // zig-zig
					rotate(p, flag), rotate(u, flag);
				}else{ // zig-zag
					rotate(u, flag), rotate(u, !flag);
				}
			}
		}
		u->push();
	}
	node* access(node* u){
		node* last = nullptr;
		for(node* v = u; v; v = v->par){
			splay(v);
			v->right = last;
			v->eval();
			last = v;
		}
		splay(u);
		return last;
	}
	bool connected(node* u, node* v){
		access(u), access(v);
		return u == v || u->par;
	}
	void link(node* u, node* v){
		evert(u), u->par = v;
	}
	void cut(node* u){
		access(u);
		u->left->par = nullptr, u->left = nullptr, u->eval();
	}
	void cut(node* u, node* v){
		access(u), access(v);
		if(u->isRoot()) u->par = nullptr;
		else v->left->par = nullptr, v->left = nullptr, v->eval();
	}
	node* lca(node* u, node* v){
		access(u);
		return access(v);
	}
	void evert(node* u){
		access(u);
		u->rev = !(u->rev), u->push();
	}
	int depth(node* u){
		access(u);
		return u->sz - 1;
	}
	void toRoot_range(node* u, const T x){
		access(u);
		opr1(u->lazy, x), u->push();
	}
	void toRoot_query(node* u){
		access(u);
		return u->al;
	}
	void range(node* u, node* v, const T x){
		evert(u), access(v);
		opr1(v->lazy, x), v->push();
	}
	T query(node* u, node* v){
		evert(u), access(v);
		return v->al;
	}
 
public:
	const int V;
	node** arr;
	LinkCutTree(const vector<T>& init_node_value)
	 : V((int)init_node_value.size()){
		arr = new node*[V];
		for(int i = 0; i < V; ++i){
			arr[i] = new node(init_node_value[i]);
		}
	}
	// ~LinkCutTree(){
	//     for(int i = 0; i < V; ++i){
	//         delete arr[i];
	//     }
	//     delete[] arr;
	// }
	// id1 と id2 が同じ木(連結成分)に属するか
	bool connected(int id1, int id2){ return connected(arr[id1], arr[id2]); }
	// id1 を id2 の non-preferred edge にする
	void link(int id1, int id2){ return link(arr[id1], arr[id2]); }
	// id とその親の間の辺を削除する
	void cut(int id){ return cut(arr[id]); }
	// id と id2 の間の辺を削除する
	void cut(int id1, int id2){ return cut(arr[id1], arr[id2]); }
	// id1 と id2 の LCA を求める
	int lca(int id1, int id2){ return static_cast<size_t>(lca(arr[id1], arr[id2]) - arr[0]); }
	// 元の木の根を id にする
	void evert(int id){ return evert(arr[id]); }
	// id の深さを求める
	int depth(int id){ return depth(arr[id]); }
	// id から根までの間にある頂点すべてに x を足す
	void toRoot_range(int id, const T x){ return toRoot_range(arr[id], x); }
	// id から根までの間にある頂点すべてのコストの総和を求める
	void toRoot_query(int id){ return toRoot_query(arr[id]); }
	// id1 と id2 の間にある頂点すべてに x を足す
	void range(int id1, int id2, const T x){ return range(arr[id1], arr[id2], x); }
	// id1 と id2 の間にある頂点すべてのコストの総和を求める
	T query(int id1, int id2){ return query(arr[id1], arr[id2]); }
};
int main(){
	ll n,Q;
	cin >> n;
	vector<ll> x(n,0);
	LinkCutTree<ll> t(x);
	FOR(i,0,n){
		int k,c;
		cin >> k;
		FOR(j,0,k){
			cin >> c;
			t.link(c,i);
		}
	}
	cin >> Q;
	FOR(q,0,Q){
		ll com,v,w,u;
		cin >> com;
		if(com){
			cin >> u;
			cout << t.query(0,u)-t.query(0,0) << endl;
		}else{
			cin >> v >> w;
			t.range(0,v,w);
		}
	}
}