#include <bits/stdc++.h>
using namespace std;
void inc_cost(long long u, long long v, long long w,
              unordered_map<long long, long long>& hash) {
  while (u != v) {
    if (u > v) {
      hash[u] += w;
      u = u / 2;
    } else {
      hash[v] += w;
      v = v / 2;
    }
  }
}
long long find(long long u, long long v,
               unordered_map<long long, long long>& hash) {
  long long total = 0;
  while (u != v) {
    if (u > v) {
      if (hash.count(u) > 0) {
        total += hash[u];
      }
      u = u / 2;
    } else {
      if (hash.count(v) > 0) {
        total += hash[v];
      }
      v = v / 2;
    }
  }
  return total;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, q, u, v, w;
  unordered_map<long long, long long> hash;
  cin >> q;
  while (q--) {
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      inc_cost(u, v, w, hash);
    } else {
      cin >> u >> v;
      cout << find(u, v, hash) << "\n";
    }
  }
}
