#include <bits/stdc++.h>
using namespace std;
int main() {
  map<pair<long long, long long>, long long> pay;
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    if (n == 1) {
      long long x, y, w;
      cin >> x >> y >> w;
      long long high = max(x, y);
      long long low = min(x, y);
      long long h = high;
      long long l = low;
      while (h != l) {
        if (l < h) {
          pay[make_pair(h, h / 2)] += w;
          h /= 2;
        } else {
          pay[make_pair(l, l / 2)] += w;
          l /= 2;
        }
      }
    } else {
      long long x, y;
      cin >> x >> y;
      long long high = max(x, y);
      long long low = min(x, y);
      long long h = high;
      long long l = low;
      long long ans = 0;
      while (h != l) {
        if (l < h) {
          ans += pay[make_pair(h, h / 2)];
          h /= 2;
        } else {
          ans += pay[make_pair(l, l / 2)];
          l /= 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
