#include <bits/stdc++.h>
using namespace std;
bool p(long long v1, long long v2) {
  for (long long g = v1; g >= 1; g /= 2)
    if (g == v2) return 1;
  return 0;
}
long long pred(long long l, long long r) {
  for (long long G = l; G >= 1; G /= 2)
    if (p(r, G)) return G;
}
map<long long, long long> m1, m2;
int n, k;
long long l, r, c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k == 1) {
      cin >> l >> r >> c;
      long long h = pred(l, r);
      for (long long j = l; j > h; j /= 2) {
        if (j % 2 == 1) {
          m1[j / 2] += c;
        } else {
          m2[j / 2] += c;
        }
      }
      for (long long j = r; j > h; j /= 2) {
        if (j % 2 == 1) {
          m1[j / 2] += c;
        } else {
          m2[j / 2] += c;
        }
      }
    } else {
      cin >> l >> r;
      long long h = pred(l, r);
      long long ans = 0;
      for (long long j = l; j > h; j /= 2) {
        if (j % 2 == 1) {
          ans += m1[j / 2];
        } else {
          ans += m2[j / 2];
        }
      }
      for (long long j = r; j > h; j /= 2) {
        if (j % 2 == 1) {
          ans += m1[j / 2];
        } else {
          ans += m2[j / 2];
        }
      }
      cout << ans << "\n";
    }
  }
}
