#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q, v, u, w, c;
  cin >> q;
  unordered_map<long long, long long> m;
  while (q--) {
    cin >> c >> v >> u;
    if (c == 1) {
      cin >> w;
      while (v != u) {
        if (v > u) {
          m[v] += w;
          v /= 2;
        } else {
          m[u] += w;
          u /= 2;
        }
      }
    } else {
      long long sum = 0;
      while (v != u) {
        if (v > u) {
          sum += m[v];
          v /= 2;
        } else {
          sum += m[u];
          u /= 2;
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
