#include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)1e5 + 9;
const long long mod = (long long)1e9 + 7;
map<long long, long long> maps;
long long lca(long long, long long, long long);
int main() {
  long long i, j, k, t, q, m, l, r, n, ans;
  cin >> q;
  while (q--) {
    cin >> j >> l >> r;
    if (j == 1) {
      cin >> m;
      lca(l, r, m);
    } else if (j == 2) {
      cout << lca(l, r, -1) << '\n';
    }
  }
}
long long lca(long long u, long long v, long long w) {
  if (u > v) {
    u ^= v;
    v ^= u;
    u ^= v;
  }
  long long ans = 0;
  if (w >= 0) {
    while (u != v) {
      maps[v] += w;
      v >>= 1;
      if (v < u) {
        u ^= v;
        v ^= u;
        u ^= v;
      }
    }
  } else {
    while (u != v) {
      if (maps.find(v) != maps.end()) ans += maps[v];
      v >>= 1;
      if (v < u) {
        u ^= v;
        v ^= u;
        u ^= v;
      }
    }
  }
  return ans;
}
