#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; 
}


Measured memory_bytes: 21032