#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long q, x, y, w, type;
  long long ans;
  cin >> q;
  while (q--) {
    cin >> type;
    ans = 0;
    if (type == 1) {
      cin >> x >> y >> w;
      while (x != y) {
        if (x > y) {
          mp[{x, x / 2}] += w;
          x /= 2;
        } else {
          mp[{y, y / 2}] += w;
          y /= 2;
        }
      }
    } else {
      cin >> x >> y;
      while (x != y) {
        if (x > y) {
          if (mp.find({x, x / 2}) != mp.end()) ans += mp[{x, x / 2}];
          x /= 2;
        } else {
          if (mp.find({y, y / 2}) != mp.end()) ans += mp[{y, y / 2}];
          y /= 2;
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
