#include <bits/stdc++.h>
using namespace std;
map<long long, long long> costs;
int get_height(long long x) {
  int d = 0;
  while (x > 0) {
    ++d;
    x /= 2;
  }
  return d;
}
void update_cost(long long from, long long to, long long cost) {
  int fr_h, to_h;
  fr_h = get_height(from);
  to_h = get_height(to);
  while (fr_h > to_h) {
    costs[from] += cost;
    from /= 2;
    --fr_h;
  }
  while (fr_h < to_h) {
    costs[to] += cost;
    to /= 2;
    --to_h;
  }
  while (from != to) {
    costs[to] += cost;
    costs[from] += cost;
    to /= 2;
    from /= 2;
  }
}
long long get_cost(long long from, long long to) {
  long long ans = 0;
  int fr_h, to_h;
  fr_h = get_height(from);
  to_h = get_height(to);
  map<long long, long long>::iterator it;
  while (fr_h > to_h) {
    it = costs.find(from);
    if (it != costs.end()) {
      ans += it->second;
    }
    from /= 2;
    --fr_h;
  }
  while (fr_h < to_h) {
    it = costs.find(to);
    if (it != costs.end()) {
      ans += it->second;
    }
    to /= 2;
    --to_h;
  }
  while (from != to) {
    it = costs.find(from);
    if (it != costs.end()) {
      ans += it->second;
    }
    it = costs.find(to);
    if (it != costs.end()) {
      ans += it->second;
    }
    to /= 2;
    from /= 2;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long mode, from, to, cost;
    cin >> mode;
    if (mode == 1) {
      cin >> from >> to >> cost;
      update_cost(from, to, cost);
    } else {
      cin >> from >> to;
      cout << get_cost(from, to) << endl;
    }
  }
  return 0;
}
