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>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define NUM 100005

struct Edge{
	Edge(int arg_to){
		to = arg_to;
	}
	int to;
};

struct Data{
	int parent,head,depth,size;
	ll sum_add_weight;
};

int V,N;
int root,global_index;
int index_table[NUM];
ll K;
ll uniformity[8*NUM],partial[8*NUM];
Data data[NUM];
vector<Edge> G[NUM];

void init(int first_N){
	while(N < first_N)N *= 2;
}

void add_and_updateNodes(int left,int right,ll value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right)return; //範囲に重なりがなければ何もしない
	else if(left <= node_left && right >= node_right){ //このノードがカバーしている区間が、集計区間の部分区間になっている場合
		uniformity[node_id] += value; //「一様に加えられた値」を加算する
	}else{ //部分的な重なりがある場合
		partial[node_id] += (min(right,node_right)-max(left,node_left)+1)*value;
		add_and_updateNodes(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2); //左の子に処理を投げる
		add_and_updateNodes(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right); //右の子に処理を投げる
	}
}

//再帰的に和を計算し、返却する関数
ll getSum(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return 0;
	else if(left <= node_left && right >= node_right){ //このノードがカバーしている区間が、集計区間の部分区間になっている場合
		return (node_right-node_left+1)*uniformity[node_id]+partial[node_id];
	}else{ //部分的に一致している場合
		ll sum = (min(right,node_right)-max(left,node_left)+1)*uniformity[node_id];
		sum += getSum(left,right,2*node_id+1,node_left,(node_left+node_right)/2); //左の子の和を加算
		sum += getSum(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right); //右の子の和を加算
		return sum;
	}
}

void add(int node_id,ll value){

	int head_node;

	while(true){
		head_node = data[node_id].head;

		//区間(鎖)に値を足す(セグ木演算)
		if(head_node != node_id){
			add_and_updateNodes(index_table[head_node],index_table[node_id],value,0,0,N-1);
		}

		if(head_node == root)break; //rootまで到達したらbreak

		data[head_node].sum_add_weight += value; //鎖間の重み

		node_id = data[head_node].parent;

		if(node_id == root)break;
	}
}


int makeTree(int node_id,int parent,int depth){

	data[node_id].depth = depth;
	data[node_id].parent = parent;
	data[node_id].sum_add_weight = 0; //鎖間の重みを保持
	data[node_id].size = 1; //部分木のノード数(自分&子孫)

	int child;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent)continue;

		data[node_id].size += makeTree(child,node_id,depth+1);
	}

	return data[node_id].size;
}

void HLD(int node_id,int head,int parent){

	index_table[node_id] = global_index++; //★★根に近いものほど、番号が小さい(★左にある★)
	data[node_id].head = head;

	if(G[node_id].size() == 0)return;

	//子の中で、最大の重み(部分木のノード数)を持つものを探す
	int max_size = -BIG_NUM;
	int max_node_id = -1,child;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent)continue;

		if(max_size < data[child].size){

			max_size = data[child].size;
			max_node_id = child;
		}
	}

	if(max_node_id == -1)return;

	//最大の重みを持つ子へ(headは変わらず)
	HLD(max_node_id,head,node_id);

	//その他の子を処理(新しいラインを作る)
	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent || child == max_node_id)continue;

		HLD(child,child,node_id);
	}
}

//node_id～rootへのコストを求める
ll get_weight(int node_id){

	ll ret = 0;
	int head_node;

	while(true){

		head_node = data[node_id].head;

		//node_id～同じラインのヘッドのコストを求める(セグ木演算)
		if(head_node != node_id){
			ret += getSum(index_table[head_node],index_table[node_id],0,0,N-1); //一様に加えられた値
			ret -= getSum(index_table[head_node],index_table[head_node],0,0,N-1);
		}

		if(head_node == root){
			break; //rootまで到達したらbreak
		}

		ret += data[head_node].sum_add_weight; //鎖間の重み

		node_id = data[head_node].parent;

		if(node_id == root)break;
	}

	return ret;
}

int main(){

	int first_N;

	scanf("%d",&first_N);

	int num;
	int from,to;

	for(from = 0; from <= first_N-1; from++){

		scanf("%d",&num);
		for(int i = 0; i < num; i++){
			scanf("%d",&to);
			G[from].push_back(Edge(to));
			G[to].push_back(Edge(from));
		}
	}

	root = 0;

	makeTree(root,-1,0);
	global_index = 0;
	HLD(root,root,-1);  //0スタートでdfs木を作ったので、0がrootとなる

	//dfs木をセグメント木に変換する
	N = 1;
	init(first_N);

	for(int i = 0; i < N; i++){

		partial[i] = 0;
		uniformity[i] = 0;
	}

	int num_query;
	scanf("%d",&num_query);

	int node_id,command,add_weight;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		if(command == 0){

			scanf("%d %d",&node_id,&add_weight);
			add(node_id,add_weight);

		}else{
			scanf("%d",&node_id);
			printf("%lld\n",get_weight(node_id));
		}
	}

	return 0;
}

