#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
long long res;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int com;
    long long u, v, w;
    scanf("%d", &com);
    if (com == 1) {
      cin >> u >> v >> w;
      while (u != v) {
        if (u < v) swap(u, v);
        mp[u] += w;
        u >>= 1;
      }
    } else {
      cin >> u >> v;
      res = 0;
      while (u != v) {
        if (u < v) swap(u, v);
        res += mp[u];
        u >>= 1;
      }
      cout << res << endl;
    }
  }
  return 0;
}
