#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, type;
  unsigned long long c, ans, a, b;
  map<unsigned long long, unsigned long long> m;
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> a >> b >> c;
      while (a != b) {
        if (a < b) swap(a, b);
        m[a] += c;
        a /= 2;
      }
    } else {
      cin >> a >> b;
      ans = 0;
      while (a != b) {
        if (a < b) swap(a, b);
        ans += m[a];
        a /= 2;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
