#include <bits/stdc++.h>
using namespace std;
long long int lca(long long int a, long long int b) {
  stack<long long int> s1;
  stack<long long int> s2;
  long long int temp = a;
  s1.push(temp);
  while (temp != 1) {
    temp = temp / 2;
    s1.push(temp);
  }
  temp = b;
  s2.push(temp);
  while (temp != 1) {
    temp = temp / 2;
    s2.push(temp);
  }
  long long int ans = 1;
  while (!s1.empty() && !s2.empty()) {
    if (s1.top() == s2.top()) {
      ans = s1.top();
      s1.pop();
      s2.pop();
    } else if (s1.top() < s2.top()) {
      s1.pop();
    } else {
      s2.pop();
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  long long int q;
  long long int s;
  long long int t, u, v, cost;
  map<long long int, long long int> hash;
  cin >> q;
  long long int temp;
  long long int ans;
  for (long long int i = 0; i < q; i++) {
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> cost;
      s = lca(u, v);
      temp = u;
      while (temp != s) {
        hash[temp] += cost;
        temp /= 2;
      }
      temp = v;
      while (temp != s) {
        hash[temp] += cost;
        temp /= 2;
      }
    } else {
      cin >> u >> v;
      s = lca(u, v);
      temp = u;
      ans = 0;
      while (temp != s) {
        ans += hash[temp];
        temp /= 2;
      }
      temp = v;
      while (temp != s) {
        ans += hash[temp];
        temp /= 2;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
