#include <bits/stdc++.h>
using namespace std;
map<long long, long long> weight;
long long lca(long long u, long long v, long long w = 0LL) {
  if (u > v) swap(u, v);
  long long ans = 0LL;
  while (u != v) {
    if (u < v) swap(u, v);
    weight[u] += w;
    ans += weight[u];
    u >>= 1LL;
  }
  return ans;
}
int q, cho;
long long a, b, w;
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d %I64d %I64d", &cho, &a, &b);
    if (cho == 1) {
      scanf("%I64d", &w);
      lca(a, b, w);
    } else {
      printf("%I64d\n", lca(a, b));
    }
  }
}
