#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> mlc;
void add(long long x, long long y, int val) {
  while (x != y) {
    if (x > y) {
      mlc[x] += val;
      x /= 2;
    } else {
      mlc[y] += val;
      y /= 2;
    }
  }
}
long long query(long long x, long long y) {
  long long ans = 0;
  while (x != y) {
    if (x > y) {
      ans += mlc[x];
      x /= 2;
    } else {
      ans += mlc[y];
      y /= 2;
    }
  }
  return ans;
}
int main() {
  int q;
  cin >> q;
  for (; q; q--) {
    int op;
    long long x, y;
    cin >> op >> x >> y;
    if (op == 1) {
      int val;
      cin >> val;
      add(x, y, val);
    } else {
      long long ans = query(x, y);
      cout << ans << '\n';
    }
  }
  return 0;
}
