#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> g;
void increase(long long x, long long y, long long c) {
  while (x != y) {
    if (x < y) {
      g[pair<long long, long long>(y / 2, y)] += c;
      y /= 2;
    } else {
      g[pair<long long, long long>(x / 2, x)] += c;
      x /= 2;
    }
  }
}
long long walk(long long x, long long y) {
  long long ret = 0;
  while (x != y) {
    if (x < y) {
      ret += g[pair<long long, long long>(y / 2, y)];
      y /= 2;
    } else {
      ret += g[pair<long long, long long>(x / 2, x)];
      x /= 2;
    }
  }
  return ret;
}
int q, t, w;
long long sol, u, v;
int main() {
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%I64d%I64d", &t, &u, &v);
    if (t == 1) {
      scanf("%d", &w);
      increase(u, v, w);
    } else {
      printf("%I64d\n", walk(u, v));
    }
  }
  return 0;
}
