#include <bits/stdc++.h>
using namespace std;
int q, t;
long long x, a, b;
map<long long, long long> M;
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d%lld%lld", &t, &a, &b);
    if (t == 1) {
      scanf("%lld", &x);
      while (a != b) {
        if (a < b) swap(a, b);
        M[a] += x, a /= 2;
      }
    } else {
      long long ans = 0;
      while (a != b) {
        if (a < b) swap(a, b);
        ans += M[a], a /= 2;
      }
      printf("%lld\n", ans);
    }
  }
}
