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