#include <bits/stdc++.h>
using namespace std;
map<long long, long long> fee;
int q, type;
long long u, v, w;
int depth(long long p) {
  if (p == 1)
    return 1;
  else
    return 1 + depth(p / 2);
}
long long lca(long long u, long long v) {
  while (depth(u) > depth(v)) u /= 2;
  while (depth(v) > depth(u)) v /= 2;
  while (u != v) u /= 2, v /= 2;
  return u;
}
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%I64d%I64d%I64d", &u, &v, &w);
      long long fa = lca(u, v);
      while (u != fa) {
        if (fee.find(u) != fee.end())
          fee[u] += w;
        else
          fee[u] = w;
        u /= 2;
      }
      while (v != fa) {
        if (fee.find(v) != fee.end())
          fee[v] += w;
        else
          fee[v] = w;
        v /= 2;
      }
    } else {
      scanf("%I64d%I64d", &u, &v);
      long long fa = lca(u, v), ans = 0;
      while (u != fa) {
        if (fee.find(u) != fee.end()) ans += fee[u];
        u /= 2;
      }
      while (v != fa) {
        if (fee.find(v) != fee.end()) ans += fee[v];
        v /= 2;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
