#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long i, n;
  cin >> n;
  map<pair<long long, long long>, long long> m;
  for (i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    if (x == 1) {
      long long a, b, w;
      cin >> a >> b >> w;
      while (a != b) {
        if (a < b) swap(a, b);
        long long x = a / 2;
        m[{x, a}] += w;
        a = x;
      }
    } else {
      long long a, b, s = 0;
      cin >> a >> b;
      while (a != b) {
        if (a < b) swap(a, b);
        long long x = a / 2;
        s += m[{x, a}];
        a = x;
      }
      cout << s << "\n";
    }
  }
}
