#include <bits/stdc++.h>
using namespace std;
long long int fin() {
  long long int x;
  scanf("%lld", &x);
  return x;
}
void func() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
pair<long long int, long long int> p;
map<pair<long long int, long long int>, long long int> mp;
int main() {
  long long int i, j, k, u, v, w, l, n, t;
  n = fin();
  while (n--) {
    k = fin();
    if (k == 1) {
      u = fin();
      v = fin();
      w = fin();
      while (v != u) {
        if (v < u) {
          p.first = u;
          p.second = u / 2;
          mp[p] += w;
          u = u / 2;
        } else {
          p.first = v;
          p.second = v / 2;
          mp[p] += w;
          v = v / 2;
        }
      }
    } else if (k == 2) {
      long long int ans = 0;
      u = fin();
      v = fin();
      while (v != u) {
        if (v < u) {
          p.first = u;
          p.second = u / 2;
          ans += mp[p];
          u = u / 2;
        } else {
          p.first = v;
          p.second = v / 2;
          ans += mp[p];
          v = v / 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
