#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, q, i, j, k, x, y, z, flag, f, ans;
  scanf("%I64d", &q);
  map<pair<long long, long long>, long long>::iterator it;
  map<pair<long long, long long>, long long> h;
  while (q--) {
    scanf("%I64d", &n);
    scanf("%I64d", &x);
    scanf("%I64d", &y);
    j = x, k = y;
    while (j != k) {
      if (j > k)
        j /= 2;
      else
        k /= 2;
    }
    if (n - 1) {
      ans = 0;
      while (x != k) {
        it = h.find(make_pair(x, x / 2));
        if (it != h.end()) ans += h[make_pair(x, x / 2)];
        x /= 2;
      }
      while (y != k) {
        it = h.find(make_pair(y, y / 2));
        if (it != h.end()) ans += h[make_pair(y, y / 2)];
        y /= 2;
      }
      printf("%I64d", ans);
      printf("\n");
    } else {
      scanf("%I64d", &z);
      while (x != k) {
        h[make_pair(x, x / 2)] += z;
        x /= 2;
      }
      while (y != k) {
        h[make_pair(y, y / 2)] += z;
        y /= 2;
      }
    }
  }
  return 0;
}
