#include <bits/stdc++.h>
using namespace std;
const int N = 300100;
const int M = 2000100;
const long long mod = 1e9 + 7;
map<long long, long long> ma;
int dep(long long p) {
  for (long long i = 1; i <= 63; i++) {
    if ((1ll << i) > p) return i - 1;
  }
}
void add(long long p, long long q, long long w) {
  if (dep(p) < dep(q)) swap(p, q);
  int h = dep(q);
  while (dep(p) != h) {
    ma[p] += w;
    p /= 2ll;
  }
  while (p != q) {
    ma[p] += w, ma[q] += w;
    p /= 2ll, q /= 2ll;
  }
}
long long solve(long long p, long long q) {
  long long ans = 0;
  if (dep(p) < dep(q)) swap(p, q);
  int h = dep(q);
  while (dep(p) != h) {
    ans += ma[p];
    p /= 2ll;
  }
  while (p != q) {
    ans += ma[p];
    ans += ma[q];
    p /= 2ll, q /= 2ll;
  }
  return ans;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long p, u, v, w;
    scanf("%lld", &p);
    if (p == 1) {
      scanf("%lld%lld%lld", &u, &v, &w);
      add(u, v, w);
    } else {
      scanf("%lld%lld", &u, &v);
      printf("%lld\n", solve(u, v));
    }
  }
  return 0;
}
