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"

class HLDecomposition
{
    int n, pos;
    std::vector<std::vector<int>> g;
    // vid:=HLD後のグラフでのid, head:=属するheavy path の head, sub:=子孫数
    // hvy:=heavy path 上の次の頂点, par:=parent, dep:=depth, inv:=vidの逆, type:=森用
    std::vector<int> vid, head, sub, hvy, par, dep, inv, type;

    void dfs(int cur)
    {
        for (auto nxt : g[cur])
        {
            if (nxt == par[cur])
                continue;
            par[nxt] = cur;
            dep[nxt] = dep[cur] + 1;
            dfs(nxt);
        }
        int ret = 0;
        for (auto u : g[cur])
        {
            if (u == par[cur])
                continue;
            sub[cur] += sub[u];
            if (ret < sub[u])
            {
                ret = sub[u];
                hvy[cur] = u;
            }
        }
    }

    void bfs(int r, int c)
    {
        std::queue<int> que({r});
        while (!que.empty())
        {
            int h = que.front();
            que.pop();
            for (int i = h; i != -1; i = hvy[i])
            {
                type[i] = c;
                vid[i] = pos++;
                inv[vid[i]] = i;
                head[i] = h;
                for (int j : g[i])
                    if (j != par[i] && j != hvy[i])
                        que.push(j);
            }
        }
    }

public:
    HLDecomposition() {}
    HLDecomposition(int sz) : n(sz), pos(0), g(n),
                              vid(n, -1), head(n), sub(n, 1), hvy(n, -1),
                              par(n, -1), dep(n, 0), inv(n), type(n) {}

    void add_edge(int u, int v)
    {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    void build(std::vector<int> rs = std::vector<int>(1, 0))
    {
        int c = 0;
        for (int r : rs)
        {
            dfs(r);
            bfs(r, c++);
        }
    }

    // f(l, r) := [l, r] に対する演算
    void for_each_vertex(int u, int v, const std::function<void(int, int)> &f)
    {
        while (true)
        {
            if (vid[u] > vid[v])
                std::swap(u, v);
            f(std::max(vid[head[v]], vid[u]), vid[v]);
            if (head[u] == head[v])
                break;
            v = par[head[v]];
        }
    }

    // f(l, r) := [l, r] に対する演算
    void for_each_edge(int u, int v, const std::function<void(int, int)> &f)
    {
        while (true)
        {
            if (vid[u] > vid[v])
                std::swap(u, v);
            if (head[u] == head[v])
            {
                if (u != v)
                    f(vid[u] + 1, vid[v]);
                break;
            }
            f(vid[head[v]], vid[v]);
            v = par[head[v]];
        }
    }

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

    int distance(int u, int v)
    {
        return dep[u] + dep[v] - 2 * dep[lca(u, v)];
    }
};

// range add range sum
class LazySegmentTree
{
    int n;
    using T1 = long long;
    using T2 = long long;
    std::vector<T1> node;
    std::vector<T2> lazy;

    // 遅延評価
    void eval(int k, int l, int r)
    {
        // 遅延配列が空なら終了
        if (lazy[k] == 0)
            return;
        // 遅延配列を適用
        node[k] = node[k] + lazy[k];
        if (r - l > 1)
        {
            lazy[2 * k + 1] = lazy[2 * k + 1] + lazy[k] / 2;
            lazy[2 * k + 2] = lazy[2 * k + 2] + lazy[k] / 2;
        }
        // 遅延配列初期化
        lazy[k] = 0;
    }

public:
    LazySegmentTree(int _n)
    {
        int sz = _n;
        n = 1;
        while (n < sz)
            n *= 2;
        // 配列初期化
        node.resize(2 * n - 1, 0);
        lazy.resize(2 * n - 1, 0);
    }
    LazySegmentTree(int _n, T1 _v)
    {
        int sz = _n;
        n = 1;
        while (n < sz)
            n *= 2;
        node.resize(2 * n - 1, 0);
        lazy.resize(2 * n - 1, 0);

        for (int i = 0; i < sz; i++)
            node[i + n - 1] = _v;
        for (int i = n - 2; i >= 0; i--)
            node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }

    // 半開区間 [a, b) に対して値 val を反映させる
    void update(int a, int b, T2 val, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        // ノード k で遅延評価
        eval(k, l, r);
        if (b <= l || r <= a)
            return;
        // 区間が被覆されている場合
        if (a <= l && r <= b)
        {
            // 遅延配列更新, 評価
            lazy[k] = lazy[k] + (r - l) * val;
            eval(k, l, r);
        }
        else
        {
            // 子ノードの値を評価し, 更新
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2 * k + 1);
            update(a, b, val, mid, r, 2 * k + 2);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    // 半開区間 [a, b) に対してクエリを投げる
    T1 query(int a, int b, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        eval(k, l, r);
        // 範囲外なら単位元返す
        if (b <= l || r <= a)
            return 0;
        if (a <= l && r <= b)
            return node[k];
        int mid = (l + r) / 2;
        T1 vl = query(a, b, l, mid, 2 * k + 1);
        T1 vr = query(a, b, mid, r, 2 * k + 2);
        return vl + vr;
    }
};

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3943554
void solve_grl_5_d()
{
    int n;
    cin >> n;
    HLDecomposition hld(n);
    LazySegmentTree lst(n);
    vector<int> par(n, -1);
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int c;
            cin >> c;
            hld.add_edge(i, c);
            par[c] = i;
        }
    }
    hld.build();
    int q;
    cin >> q;
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int v, w;
            cin >> v >> w;
            hld.for_each_edge(par[v], v, [&](int l, int r) {
                lst.update(l, r + 1, w);
            });
            continue;
        }
        int u;
        cin >> u;
        long long ret = 0;
        hld.for_each_edge(0, u, [&](int l, int r) {
            ret += lst.query(l, r + 1);
        });
        cout << ret << endl;
    }
}

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3943586
void solve_grl_5_e()
{
    int n;
    cin >> n;
    HLDecomposition hld(n);
    LazySegmentTree lst(n);
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int c;
            cin >> c;
            hld.add_edge(i, c);
        }
    }
    hld.build();
    int q;
    cin >> q;
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int v, w;
            cin >> v >> w;
            hld.for_each_edge(0, v, [&](int l, int r) {
                lst.update(l, r + 1, w);
            });
            continue;
        }
        int u;
        cin >> u;
        long long ret = 0;
        hld.for_each_edge(0, u, [&](int l, int r) {
            ret += lst.query(l, r + 1);
        });
        cout << ret << endl;
    }
}

// 頂点クエリテストしてない
void solve_yukicoder_399()
{
    using ll = long long;
    int n;
    cin >> n;
    HLDecomposition hld(n);
    LazySegmentTree lst(n + 10);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        hld.add_edge(u, v);
    }
    hld.build();
    for (int i = 0; i < n; i++)
    {
        hld.for_each_vertex(i, i, [&](int l, int r) {
            lst.update(l, r + 1, 1);
        });
    }
    int q;
    cin >> q;
    ll ret = 0;
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        hld.for_each_vertex(a, b, [&](int l, int r) {
            ret += lst.query(l, r + 1);
        });
        hld.for_each_vertex(a, b, [&](int l, int r) {
            lst.update(l, r + 1, 1);
        });
    }
    cout << ret << endl;
}

int main()
{
    solve_grl_5_e();
}

