#include <bits/stdc++.h>
using namespace std;
struct yts {
  long long x, y, w, z;
} q[1010];
long long ans;
int n, T, num;
long long DEP(long long x) {
  long long num = 0;
  while (x != 1) x >>= 1, num++;
  return num;
}
long long LCA(long long x, long long y) {
  long long depx = DEP(x), depy = DEP(y);
  while (depx > depy) x >>= 1, depx--;
  while (depy > depx) y >>= 1, depy--;
  while (x != y) x >>= 1, y >>= 1;
  return x;
}
long long calc(long long x, long long y, int k) {
  long long X1 = LCA(x, q[k].x), X2 = LCA(x, q[k].y), X;
  if (DEP(X1) > DEP(X2))
    X = X1;
  else
    X = X2;
  long long Y1 = LCA(y, q[k].x), Y2 = LCA(y, q[k].y), Y;
  if (DEP(Y1) > DEP(Y2))
    Y = Y1;
  else
    Y = Y2;
  return max(DEP(X), DEP(q[k].z)) + max(DEP(Y), DEP(q[k].z)) -
         2 * max(DEP(LCA(X, Y)), DEP(q[k].z));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int op;
    scanf("%d", &op);
    if (op == 1)
      num++, scanf("%I64d%I64d%I64d", &q[num].x, &q[num].y, &q[num].w),
          q[num].z = LCA(q[num].x, q[num].y);
    else {
      ans = 0;
      long long x, y;
      scanf("%I64d%I64d", &x, &y);
      for (int j = 1; j <= num; j++) ans += calc(x, y, j) * q[j].w;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
