#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
bool ok(long long a, long long b) {
  while (b > a) {
    b /= 2;
  }
  return (b == a);
}
map<long long, long long> ma;
long long go(long long u, long long v, long long w) {
  while (!ok(u, v)) {
    ma[u] += w;
    u /= 2;
  }
  while (v != u) {
    ma[v] += w;
    v /= 2;
  }
}
long long sol(long long u, long long v) {
  long long res = 0;
  while (!ok(u, v)) {
    res += ma[u];
    u /= 2;
  }
  while (v != u) {
    res += ma[v];
    v /= 2;
  }
  return res;
}
int main() {
  int q, t;
  long long u, v, w;
  cin >> q;
  while (q--) {
    cin >> t >> u >> v;
    if (t == 1) {
      cin >> w;
      go(u, v, w);
    } else
      cout << sol(u, v) << endl;
  }
  return 0;
}
