#include <bits/stdc++.h>
using namespace std;
map<long long, long long> lft, rght;
int level(long long i) {
  int l = 0;
  while (i) {
    l++;
    i = i >> 1;
  }
  return l;
}
long long lcp(long long a, long long b) {
  int la = level(a), lb = level(b);
  int offset = abs(lb - la);
  a <<= offset;
  long long ret = 0;
  for (int i = 0; i < la; i++) {
    if ((a & ((long long)1 << (lb - i - 1))) ==
        (b & ((long long)1 << (lb - i - 1)))) {
      ret = ret << 1;
      if (a & ((long long)1 << (lb - i - 1))) {
        ret |= 1;
      }
    } else {
      break;
    }
  }
  return ret;
}
void add_path_direct(long long u, long long v, long long w, int offset) {
  for (int i = offset - 1; i >= 0; i--) {
    if (v & ((long long)1 << i)) {
      rght[u] += w;
      u = (u << 1) + 1;
    } else {
      lft[u] += w;
      u = u << 1;
    }
  }
}
void add_path(long long u, long long v, long long w) {
  if (u > v) swap(u, v);
  long long _lcp = lcp(u, v);
  int lu = level(u), lv = level(v);
  add_path_direct(_lcp, u, w, lu - level(_lcp));
  add_path_direct(_lcp, v, w, lv - level(_lcp));
}
long long query_path_direct(long long u, long long v, int offset) {
  long long ret = 0;
  for (int i = offset - 1; i >= 0; i--) {
    if (v & ((long long)1 << i)) {
      ret += rght[u];
      u = (u << 1) + 1;
    } else {
      ret += lft[u];
      u = u << 1;
    }
  }
  return ret;
}
long long query_path(long long u, long long v) {
  if (u > v) swap(u, v);
  long long _lcp = lcp(u, v);
  int lu = level(u), lv = level(v);
  return query_path_direct(_lcp, u, lu - level(_lcp)) +
         query_path_direct(_lcp, v, lv - level(_lcp));
}
int main() {
  int q;
  long long op, u, v, w;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> op >> u >> v;
    if (op == 1) {
      cin >> w;
      add_path(u, v, w);
    } else {
      cout << query_path(u, v) << endl;
    }
  }
}
