#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, unsigned long long> a;
unsigned long long n, u, v;
unsigned long long cost;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    long long k;
    cin >> k;
    if (k & 1) {
      cin >> u >> v >> cost;
      while (u != v) {
        if (u < v) swap(u, v);
        a[make_pair(u, u / 2)] += cost;
        u /= 2;
      }
    } else {
      unsigned long long sum = 0;
      cin >> u >> v;
      while (u != v) {
        if (u < v) swap(u, v);
        sum += a[make_pair(u, u / 2)];
        u /= 2;
      }
      cout << sum << "\n";
    }
  }
}
