#include <bits/stdc++.h>
using namespace std;
int q, op, w;
long long x, y;
map<long long, long long> f;
long long dep(long long x) {
  long long t = 0;
  while (x) x /= 2, t++;
  return t;
}
void change(long long x, long long y, long long w) {
  long long dx = dep(x), dy = dep(y);
  while (x != y) {
    if (dx > dy) {
      f[x] += w;
      x /= 2;
      dx--;
    } else {
      f[y] += w;
      y /= 2;
      dy--;
    }
  }
}
long long ask(long long x, long long y) {
  long long dx = dep(x), dy = dep(y);
  long long t = 0;
  while (x != y) {
    if (dx > dy) {
      t += f[x];
      x /= 2;
      dx--;
    } else {
      t += f[y];
      y /= 2;
      dy--;
    }
  }
  return t;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d%I64d%I64d", &op, &x, &y);
    if (op == 1) {
      scanf("%d", &w);
      change(x, y, w);
    } else {
      printf("%I64d\n", ask(x, y));
    }
  }
  return 0;
}
