#include <bits/stdc++.h>
using namespace std;
map<long long, int> A, B;
int sum = 1;
long long mark[300000];
long long lca(long long x, long long y) {
  B.clear();
  while (x) {
    B[x]++;
    x /= 2;
  }
  while (y) {
    if (B[y]) return y;
    y /= 2;
  }
}
int main() {
  int n;
  long long q, x, y, z;
  scanf("%d", &n);
  while (n--) {
    scanf("%I64d%I64d%I64d", &q, &x, &y);
    if (x >= y) swap(x, y);
    if (q == 1) {
      scanf("%I64d", &z);
      long long xx = lca(x, y);
      while (x != xx) {
        if (!A[x]) A[x] = sum++;
        mark[A[x]] += z;
        x /= 2;
      }
      while (y != xx) {
        if (!A[y]) A[y] = sum++;
        mark[A[y]] += z;
        y /= 2;
      }
    } else {
      long long xx = lca(x, y), ans = 0;
      while (x != xx) {
        ans += mark[A[x]];
        x /= 2;
      }
      while (y != xx) {
        ans += mark[A[y]];
        y /= 2;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
