#include <bits/stdc++.h>
using namespace std;
long long lca(long long a, long long b) {
  while (a != b) {
    if (a < b)
      b /= 2;
    else
      a /= 2;
  }
  return a;
}
long long inf = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  map<long long, long long> M;
  while (t-- > 0) {
    int x;
    cin >> x;
    long long u, v, w;
    cin >> u >> v;
    if (x == 1) {
      cin >> w;
      long long y = lca(u, v);
      while (u != y) {
        M[u] += w;
        u /= 2;
      }
      while (v != y) {
        M[v] += w;
        v /= 2;
      }
    } else {
      long long y = lca(u, v);
      long long ans = 0;
      while (u != y) {
        ans += M[u];
        u /= 2;
      }
      while (v != y) {
        ans += M[v];
        v /= 2;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
