#include <bits/stdc++.h>
using namespace std;
map<long long, long long> graph;
void lca(long long u, long long v, long long cost) {
  while (u != v) {
    if (u < v) swap(u, v);
    graph[u] += cost;
    u /= 2;
  }
}
long long queries(long long u, long long v) {
  long long cost = 0;
  while (u != v) {
    if (u < v) swap(u, v);
    cost += graph[u];
    u /= 2;
  }
  return cost;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int Q;
  cin >> Q;
  while (Q--) {
    int query;
    cin >> query;
    if (query == 1) {
      long long u, v, cost;
      cin >> u >> v >> cost;
      lca(u, v, cost);
    } else {
      long long u, v;
      cin >> u >> v;
      cout << queries(u, v) << "\n";
    }
  }
  return 0;
}
