#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> c;
signed main() {
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      while (u != v) {
        if (u > v) {
          c[u] += w;
          u /= 2;
        } else {
          c[v] += w;
          v /= 2;
        }
      }
    } else {
      long long cost = 0;
      long long u, v;
      cin >> u >> v;
      while (u != v) {
        if (u > v) {
          cost += c[u];
          u /= 2;
        } else {
          cost += c[v];
          v /= 2;
        }
      }
      cout << cost << '\n';
    }
  }
}
