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