#include <bits/stdc++.h>
using namespace std;
long long int parent(long long int a, long long int b) {
  set<long long int> s1, s2;
  set<long long int>::reverse_iterator it;
  s1.clear();
  s2.clear();
  long long int p;
  while (a > 0) {
    s1.insert(a);
    a /= 2;
  }
  while (b > 0) {
    s2.insert(b);
    b /= 2;
  }
  for (it = s1.rbegin(); it != s1.rend(); it++)
    if (s2.find(*it) != s2.end()) {
      p = *it;
      break;
    }
  return p;
}
int main() {
  long long int q, ch;
  cin >> q;
  map<long long int, long long int> mp;
  long long int w, a, b, p, ans;
  mp[1] = 0;
  while (q--) {
    cin >> ch;
    if (ch == 1) {
      cin >> a >> b >> w;
      p = parent(a, b);
      while (a != p) {
        if (mp.find(a) == mp.end()) mp[a] = 0;
        mp[a] += w;
        a /= 2;
      }
      while (b != p) {
        if (mp.find(b) == mp.end()) mp[b] = 0;
        mp[b] += w;
        b /= 2;
      }
    } else {
      cin >> a >> b;
      ans = 0;
      p = parent(a, b);
      while (a != p) {
        if (mp.find(a) != mp.end()) ans += mp[a];
        a /= 2;
      }
      while (b != p) {
        if (mp.find(b) != mp.end()) ans += mp[b];
        b /= 2;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
