#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = 1e9 + 10;
int qn;
struct Query {
  long long op, u, v, w;
  void read() {
    scanf("%I64d%I64d%I64d", &op, &u, &v);
    if (op == 1) scanf("%I64d", &w);
  }
};
Query q[maxn];
long long ans[maxn];
long long lc[maxn];
map<long long, long long> wt;
long long LCA(long long u, long long v) {
  while (u != v) {
    if (u > v)
      u >>= 1;
    else
      v >>= 1;
  }
  return u;
}
void add(long long x, long long i, long long w) {
  long long u = q[i].u, v = q[i].v;
  long long lca = lc[i];
  while (u != lca) {
    if (u == x) ans[i] += w;
    u >>= 1;
  }
  while (v != lca) {
    if (v == x) ans[i] += w;
    v >>= 1;
  }
}
int main() {
  while (cin >> qn) {
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= qn; i++) q[i].read();
    for (int i = 1; i <= qn; i++) lc[i] = LCA(q[i].u, q[i].v);
    wt.clear();
    for (int i = 1; i <= qn; i++) {
      long long u = q[i].u, v = q[i].v;
      if (q[i].op == 1) {
        long long w = q[i].w;
        long long lca = lc[i];
        while (u != lca) {
          wt[u] += w;
          u >>= 1;
        }
        while (v != lca) {
          wt[v] += w;
          v >>= 1;
        }
      } else {
        long long lca = lc[i];
        long long res = 0;
        while (u != lca) {
          res += wt[u];
          u >>= 1;
        }
        while (v != lca) {
          res += wt[v];
          v >>= 1;
        }
        printf("%I64d\n", res);
      }
    }
  }
  return 0;
}
