#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> a;
int n;
void solve() {
  int q, t;
  long long x, y, w, as, ans;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%lld", &x);
      scanf("%lld", &y);
      scanf("%lld", &w);
      while (x != y) {
        if (y > x) swap(x, y);
        as = x / 2;
        a[make_pair(as, x)] += w;
        a[make_pair(x, as)] += w;
        x /= 2;
      }
    } else {
      ans = 0;
      scanf("%lld", &x);
      scanf("%lld", &y);
      while (x != y) {
        if (y > x) swap(x, y);
        as = x / 2;
        ans += a[make_pair(x, as)];
        x /= 2;
      }
      cout << ans << endl;
    }
  }
  return;
}
int main() {
  int i, j;
  solve();
}
