#include <bits/stdc++.h>
int n;
using namespace std;
map<long long, long long> mp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    long long l, r, w;
    int f;
    scanf("%d", &f);
    if (f == 1) {
      scanf("%lld%lld%lld", &l, &r, &w);
      while (l != r)
        if (l > r) {
          mp[l] += w;
          l /= 2;
        } else {
          mp[r] += w;
          r /= 2;
        }
    } else {
      scanf("%lld%lld", &l, &r);
      long long ans = 0;
      while (l != r)
        if (l > r) {
          ans += mp[l];
          l /= 2;
        } else {
          ans += mp[r];
          r /= 2;
        }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
