#include <bits/stdc++.h>
using namespace std;
long long q, t, u, v, w, ans;
map<long long, map<long long, long long> > m;
void s() {
  while (u != v)
    if (u < v)
      ans += m[v][v / 2], v /= 2;
    else
      ans += m[u][u / 2], u /= 2;
}
void f() {
  while (u != v)
    if (u < v)
      m[v][v / 2] += w, v /= 2;
    else
      m[u][u / 2] += w, u /= 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      f();
    } else {
      cin >> u >> v;
      ans = 0;
      s();
      cout << ans << '\n';
    }
  }
  return 0;
}
