#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int q;
int main(void) {
  cin >> q;
  long long z, l, r, w;
  while (q--) {
    cin >> z;
    if (z == 1) {
      cin >> l >> r >> w;
      while (l != r) {
        if (l > r) {
          mp[l] += w;
          l /= 2;
        } else {
          mp[r] += w;
          r /= 2;
        }
      }
    } else {
      cin >> l >> r;
      unsigned long long ans = 0;
      while (l != r) {
        if (l > r) {
          ans += mp[l];
          l /= 2;
        } else {
          ans += mp[r];
          r /= 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
