#include <bits/stdc++.h>
using namespace std;
int n, p;
long long u, v, w, res;
map<long long, long long> a;
void cal(long long u, long long v, long long w) {
  res = 0;
  while (u != v) {
    if (u < v) swap(u, v);
    a[u] += w;
    if (w == 0) res += a[u];
    u >>= 1;
  }
}
int main() {
  cin >> n;
  while (n-- > 0) {
    cin >> p;
    if (p == 1) {
      cin >> u >> v >> w;
      cal(u, v, w);
    } else {
      cin >> u >> v;
      cal(u, v, 0);
      cout << res << endl;
    }
  }
}
