#include <bits/stdc++.h>
using namespace std;
long long przodek(long long n, long long m) {
  if (n == m) return n;
  if (n > m) return przodek(n / 2, m);
  return przodek(n, m / 2);
}
int main() {
  long long q;
  cin >> q;
  set<pair<long long, long long> > path_fee;
  for (int i = 0; i < q; i++) {
    long long op, v, u, w;
    cin >> op;
    if (op == 1) {
      cin >> u >> v >> w;
      long long prz = przodek(u, v);
      while (u != prz) {
        pair<long long, long long> act_fee = *path_fee.lower_bound({u, 0});
        if (act_fee.first == u)
          path_fee.erase(act_fee);
        else
          act_fee.second = 0;
        path_fee.insert({u, act_fee.second + w});
        u /= 2;
      }
      while (v != prz) {
        pair<long long, long long> act_fee = *path_fee.lower_bound({v, 0});
        if (act_fee.first == v)
          path_fee.erase(act_fee);
        else
          act_fee.second = 0;
        path_fee.insert({v, act_fee.second + w});
        v /= 2;
      }
      continue;
    }
    cin >> u >> v;
    long long cost = 0;
    long long prz = przodek(u, v);
    while (u != prz) {
      pair<long long, long long> act_fee = *path_fee.lower_bound({u, 0});
      if (act_fee.first == u) {
        cost += act_fee.second;
      }
      u /= 2;
    }
    while (v != prz) {
      pair<long long, long long> act_fee = *path_fee.lower_bound({v, 0});
      if (act_fee.first == v) {
        cost += act_fee.second;
      }
      v /= 2;
    }
    cout << cost << endl;
  }
}
