#include <bits/stdc++.h>
using namespace std;
long long cross_num(long long i, long long j) {
  while (i != j) {
    if (i > j)
      i >>= 1;
    else
      j >>= 1;
  }
  return i;
}
struct road_fee {
  long long up_node, end_node, fee;
};
vector<road_fee> roa;
long long fee___(long long a, long long b) {
  long long ans = 0;
  for (int i = 0; i < roa.size(); i++) {
    long long temp = cross_num(roa[i].up_node, a);
    long long temp1 = cross_num(roa[i].end_node, b);
    long long upp = max(roa[i].up_node, a);
    if (cross_num(temp1, temp) == temp)
      while (temp1 > upp) {
        temp1 >>= 1;
        ans += roa[i].fee;
      }
  }
  return ans;
};
long long search_fee(long long a, long long b) {
  long long ans = 0;
  long long temp = cross_num(a, b);
  if (temp == b)
    return fee___(temp, a);
  else if (temp == a)
    return fee___(temp, b);
  else
    return fee___(temp, b) + fee___(temp, a);
};
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    long long a, b, c, d, e;
    cin >> a;
    if (a == 1) {
      cin >> b >> d >> e;
      long long temp = cross_num(b, d);
      if (temp == b || temp == d)
        roa.push_back({min(b, d), max(b, d), e});
      else {
        roa.push_back({temp, b, e});
        roa.push_back({temp, d, e});
      }
    } else {
      cin >> b >> d;
      cout << search_fee(b, d) << endl;
    }
  }
}
