#include <bits/stdc++.h>
using namespace std;
const int size1 = 3e5;
const int INF = 2e9;
map<long long, long long> cost;
void vir(long long v, long long u, long long w) {
  while (v != u) {
    if (v > u) {
      if (cost.count(v) == 0) {
        cost[v] = w;
      } else {
        cost[v] += w;
      }
      v = v / 2;
    } else {
      if (cost.count(u) == 0) {
        cost[u] = w;
      } else {
        cost[u] += w;
      }
      u = u / 2;
    }
  }
}
long long path(long long v, long long u) {
  long long sum = 0;
  while (v != u) {
    if (v > u) {
      if (cost.count(v) != 0) {
        sum += cost[v];
      }
      v = v / 2;
    } else {
      if (cost.count(u) != 0) {
        sum += cost[u];
      }
      u = u / 2;
    }
  }
  return sum;
}
int main() {
  int q, i;
  cin >> q;
  for (i = 1; i <= q; i++) {
    int met;
    cin >> met;
    if (met == 1) {
      long long v, u, w;
      cin >> v >> u >> w;
      vir(v, u, w);
    } else {
      long long v, u;
      cin >> v >> u;
      cout << path(v, u) << endl;
    }
  }
  return 0;
}
