#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
long long update(long long u, long long v, long long w) {
  vector<long long> vec;
  long long a = u;
  long long b = v;
  if (u > v) {
    long long temp = v;
    v = u;
    u = temp;
  }
  while (v) {
    vec.push_back(v);
    v = v / 2;
  }
  reverse(vec.begin(), vec.end());
  long long k;
  while (u) {
    if (binary_search(vec.begin(), vec.end(), u)) {
      k = u;
      break;
    }
    u = u / 2;
  }
  while (a > k) {
    m[a] += w;
    a = a / 2;
  }
  while (b > k) {
    m[b] += w;
    b = b / 2;
  }
  return k;
}
long long tell(long long u, long long v) {
  long long ans = 0;
  long long k = update(u, v, 0);
  while (u > k) {
    ans += m[u];
    u = u / 2;
  }
  while (v > k) {
    ans += m[v];
    v = v / 2;
  }
  return ans;
}
int main() {
  long long q;
  cin >> q;
  long long a;
  long long ans;
  long long u, v, w;
  while (q--) {
    cin >> a;
    if (a == 1) {
      cin >> u >> v >> w;
      update(u, v, w);
    } else if (a == 2) {
      cin >> u >> v;
      ans = tell(u, v);
      cout << ans << "\n";
    }
  }
  return 0;
}
