#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e6 + 3;
const long long MAXN = 111111;
map<pair<long long, long long>, long long> fee;
long long n, q, u, v, w;
long long find(long long first, long long second) {
  set<long long> f1;
  while (first > 0) {
    f1.insert(first);
    first /= 2;
  }
  while (second > 0) {
    if (f1.count(second))
      return second;
    else
      second /= 2;
  }
  return -1;
}
void addfee(long long fa, long long first, long long w) {
  if (fa == first) return;
  vector<long long> path;
  long long t = first;
  while (t != fa) {
    if (t % 2 == 1)
      path.push_back(1);
    else
      path.push_back(0);
    t /= 2;
  }
  reverse(path.begin(), path.end());
  for (int i = 0; i < path.size(); i++) {
    long long cnt = path[i] == 0 ? fa * 2 : fa * 2 + 1;
    fee[{fa, cnt}] += w;
    fa = cnt;
  }
}
long long getfee(long long fa, long long first) {
  if (fa == first) return 0;
  vector<long long> path;
  long long t = first;
  while (t != fa) {
    if (t % 2 == 1)
      path.push_back(1);
    else
      path.push_back(0);
    t /= 2;
  }
  reverse(path.begin(), path.end());
  long long sum = 0;
  for (int i = 0; i < path.size(); i++) {
    long long cnt = path[i] == 0 ? fa * 2 : fa * 2 + 1;
    sum += fee[{fa, cnt}];
    fa = cnt;
  }
  return sum;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> q;
    if (q == 1) {
      cin >> u >> v >> w;
      long long fa = find(u, v);
      addfee(fa, u, w);
      addfee(fa, v, w);
    } else if (q == 2) {
      cin >> u >> v;
      long long fa = find(u, v);
      long long sum = 0;
      sum += getfee(fa, u);
      sum += getfee(fa, v);
      cout << sum << endl;
    }
  }
  return 0;
}
