#include <bits/stdc++.h>
using namespace std;
map<pair<long long int, long long int>, long long int> M;
map<long long int, long long int> C;
int main() {
  M.clear();
  long long int ans = 0, q, u, v, x, ch, w;
  cin >> q;
  C.clear();
  while (q--) {
    C.clear();
    cin >> ch >> u >> v;
    if (v < u) swap(v, u);
    long long int X, U = u;
    while (U >= 1) {
      C[U] = 1;
      U /= 2;
    }
    ans = 0;
    if (ch == 1) {
      cin >> w;
      while (v > 1) {
        x = v / 2;
        if (x == 0) break;
        M[make_pair(x, v)] += w;
        M[make_pair(v, x)] += w;
        if (C[x]) break;
        v = v / 2;
      }
      if (u != 1)
        while (u > x) {
          X = u / 2;
          if (X == 0) break;
          M[make_pair(u, X)] += w;
          M[make_pair(X, u)] += w;
          u /= 2;
        }
    } else {
      while (v > 1) {
        x = v / 2;
        if (x == 0) break;
        ans += M[make_pair(x, v)];
        if (C[x]) break;
        v = v / 2;
      }
      if (u != 1)
        while (u > x) {
          X = u / 2;
          if (X == 0) break;
          ans += M[make_pair(u, X)];
          u /= 2;
        }
      cout << ans << "\n";
    }
  }
  return 0;
}
