#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> t;
inline long long lca(long long v, long long u, long long w = -1) {
  long long ans = 0;
  while (v != u) {
    if (v < u) swap(v, u);
    if (t.find(v) != t.end()) ans += t[v];
    if (w != -1) t[v] += w;
    v >>= 1;
  }
  return ans;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int c;
    long long v, u, weight;
    cin >> c >> v >> u;
    if (c == 1) {
      cin >> weight;
      lca(v, u, weight);
    } else {
      cout << lca(v, u) << endl;
    }
  }
  return 0;
}
