#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mm;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long type, u, v, key;
    cin >> type >> u >> v;
    if (type == 1) {
      cin >> key;
      while (u != v) {
        if (u > v) {
          mm[u] += key;
          u /= 2;
        } else {
          mm[v] += key;
          v /= 2;
        }
      }
    } else {
      long long sum = 0;
      while (u != v) {
        if (u > v) {
          sum += mm[u];
          u /= 2;
        } else {
          sum += mm[v];
          v /= 2;
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
