#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
struct edge {
    int src,to;
    T cost;

    edge() = default;
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
    bool operator<(const edge &e) const {
        return cost < e.cost;
    }
};

template<typename T, typename U, typename F, typename G, typename H>
struct LazySegmentTree {
    T unitynode;
    U unitylazy;
    F f;
    G g;
    H h;
    int N;
    int height;
    vector<T> node;
    vector<U> lazy;

    LazySegmentTree(F f, G g, H h, T unitynode, U unitylazy) : f(f), g(g), h(h), unitynode(unitynode), unitylazy(unitylazy) {}

    void init(int sz) {
        N = 1;
        height = 0;
        while (N < sz) {
            N *= 2;
            ++height;
        }
        node.assign(2*N,unitynode);
        lazy.assign(2*N,unitylazy);
    }

    void set(int k, const T &val) {node[k+N] = val;}

    void build() {
        for (int i = N-1; i > 0; --i) {
            node[i] = f(node[i<<1|0],node[i<<1|1]);
        }
    }

    inline T reflect(int k) {
        return lazy[k] == unitylazy ? node[k] : g(node[k],lazy[k]);
    }

    void eval(int k) {
        if (lazy[k] == unitylazy) return;
        if (k < N) {
            lazy[k<<1|0] = h(lazy[k<<1|0],lazy[k]);
            lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        }
        node[k] = reflect(k);
        lazy[k] = unitylazy;
    }

    inline void recalc(int k) {
        while (k >>= 1) {
            node[k] = f(reflect(k<<1|0),reflect(k<<1|1));
        }
    }

    // [l,r) (0-indexed)
    void update(int l, int r, U val) {
        if (l >= r) return;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        int a = l; int b = r++;
        while (l < r) {
            if (l & 1) lazy[l] = h(lazy[l],val), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r],val);
            l >>= 1; r >>= 1;
        }
        recalc(a);
        recalc(b);
    }

    T get(int l, int r) {
        if (l >= r) return unitynode;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        ++r;
        T vl = unitynode, vr = unitynode;
        while (l < r) {
            if (l & 1) vl = f(vl,reflect(l++));
            if (r & 1) vr = f(reflect(--r),vr);
            l >>= 1; r >>= 1;
        }
        return f(vl,vr);
    }

    T operator[](int x) {return reflect(x+N);}
};

/*
example
auto f=[](ll a, ll b) {return min(a,b);};
auto g=[](ll a, ll b) {return b;};
auto h=[](ll a, ll b) {return b;};
ll id1 = 1e18; ll id2 = -1;
LazySegmentTree<ll, ll, decltype(f), decltype(g), decltype(h)> seg(f,g,h,id1,id2);
seg.init(N);
for (int i = 0; i < N; ++i) seg.set(i,(1LL<<31)-1);
seg.build();
*/

struct HeavyLightDecomposition {
    vector<vector<int>> G;
    vector<int> vid, head, sub, par, dep, inv, type;

    HeavyLightDecomposition(int N) :
        G(N),vid(N,-1),head(N),sub(N,1),
        par(N,-1),dep(N,0),inv(N),type(N){}

    void add_edge(int u,int v) {
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    void build(vector<int> rs={0}) {
        int c=0,pos=0;
        for(int r:rs) {
            dfs_sz(r);
            head[r]=r;
            dfs_hld(r,c++,pos);
        }
    }

    void dfs_sz(int v) {
        for(int &u:G[v]) if(u==par[v]) swap(u,G[v].back());
        if(~par[v]) G[v].pop_back();
        for(int &u:G[v]) {
            par[u]=v;
            dep[u]=dep[v]+1;
            dfs_sz(u);
            sub[v]+=sub[u];
            if(sub[u]>sub[G[v][0]]) swap(u,G[v][0]);
        }
    }

    void dfs_hld(int v,int c,int &pos) {
        vid[v]=pos++;
        inv[vid[v]]=v;
        type[v]=c;
        for(int u:G[v]){
            if(u==par[v]) continue;
            head[u]=(u==G[v][0]?head[v]:u);
            dfs_hld(u,c,pos);
        }
    }

    int lca(int u,int v){
        while(1){
            if(vid[u]>vid[v]) 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)];
    }

    // for_each(vertex)
    template<typename F>
    void for_each(int u, int v, const F& f) {
        while(1){
            if(vid[u]>vid[v]) swap(u,v);
            f(max(vid[head[v]],vid[u]),vid[v]+1);
            if(head[u]!=head[v]) v=par[head[v]];
            else break;
        }
    }

    template<typename T,typename Q,typename F>
    T for_each(int u,int v,T ti,const Q &q,const F &f){
        T l=ti,r=ti;
        while(1){
            if(vid[u]>vid[v]){
                swap(u,v);
                swap(l,r);
            }
            l=f(l,q(max(vid[head[v]],vid[u]),vid[v]+1));
            if(head[u]!=head[v]) v=par[head[v]];
            else break;
        }
        return f(l,r);
    }

    // for_each(edge)
    // [l, r) <- attention!!
    template<typename F>
    void for_each_edge(int u, int v,const F& f) {
        while(1){
            if(vid[u]>vid[v]) swap(u,v);
            if(head[u]!=head[v]){
                f(vid[head[v]],vid[v]+1);
                v=par[head[v]];
            }else{
                if(u!=v) f(vid[u]+1,vid[v]+1);
                break;
            }
        }
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    HeavyLightDecomposition HLD(N);
    rep(i,N) {
        int k; cin >> k;
        rep(j,k) {
            int c; cin >> c;
            HLD.add_edge(i,c);
        }
    }
    HLD.build();
    auto f=[](pll a, pll b) {
        a.first += b.first;
        a.second += b.second;
        return a;
    };
    auto g=[](pll a, ll val) {
        a.first += a.second*val;
        return a;
    };
    auto h=[](ll a, ll b) {return a+b;};
    const pll id1 = pll(0,0);
    const ll id2 = 0;
    LazySegmentTree<pll, ll, decltype(f), decltype(g), decltype(h)> seg(f,g,h,id1,id2);
    seg.init(N);
    rep(i,N) seg.set(i,pll(0,1));
    seg.build();

    int Q; cin >> Q;
    while (Q--) {
        int com; cin >> com;
        if (com) {
            int u; cin >> u;
            ll ans = 0;
            auto z=[&](int u, int v) {ans+=seg.get(u,v).first;};
            HLD.for_each_edge<decltype(z)>(0,u,z);
            cout << ans << ln;
        } else {
            int v,w; cin >> v >> w;
            auto zz=[&](int u, int v) {seg.update(u,v,w);};
            HLD.for_each_edge<decltype(zz)>(0,v,zz);
        }
    }
}



Measured memory_bytes: 21392