#include <bits/stdc++.h>
using namespace std;
long long n, dl, nv, l, r, z, t, ves, ans;
string s, sn;
map<pair<long long, long long>, long long> a;
char el;
int main() {
  cin >> z;
  for (int i = 1; i <= z; i++) {
    cin >> t;
    if (t == 1) {
      cin >> l >> r >> ves;
      while (l != r) {
        if (l > r) {
          nv = l / 2;
          a[make_pair(nv, l)] += ves;
          l = l / 2;
        } else {
          nv = r / 2;
          a[make_pair(nv, r)] += ves;
          r = r / 2;
        }
      }
    } else {
      cin >> l >> r;
      ans = 0;
      while (l != r) {
        if (l > r) {
          nv = l / 2;
          ans = ans + a[make_pair(nv, l)];
          l = l / 2;
        } else {
          nv = r / 2;
          ans = ans + a[make_pair(nv, r)];
          r = r / 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
