#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
long long func(long long u, long long v, int w) {
  long long ans = 0;
  while (u != v) {
    if (u > v) {
      ans += mp[u];
      mp[u] += w;
      u = u / 2;
    } else {
      ans += mp[v];
      mp[v] += w;
      v = v / 2;
    }
  }
  return ans;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      long long u, v;
      int w;
      cin >> u >> v >> w;
      long long res = func(u, v, w);
    } else {
      long long u, v;
      cin >> u >> v;
      cout << func(u, v, 0) << "\n";
    }
  }
}
