#include <bits/stdc++.h>
const long double PI(acosl(-1.0));
using namespace std;
map<pair<long long, long long>, long long> m;
void fs(long long q, long long s, long long cost) {
  long long cv = 0;
  long long qq[64], ss[64], ccv[64];
  for (long long i = 0; i < 64; i++) {
    qq[i] = q % 2;
    ss[i] = s % 2;
    ccv[i] = cv % 2;
    q /= 2, s /= 2, cv /= 2;
  }
  set<long long> ch;
  for (long long i = 63; i >= 0; i--) {
    if (qq[i] == 0) {
      cv *= 2ll;
      ch.insert(cv);
    } else {
      cv *= 2ll;
      cv++;
      ch.insert(cv);
    }
  }
  set<long long> ch1;
  cv = 0;
  for (long long i = 63; i >= 0; i--) {
    if (ss[i] == 0) {
      cv *= 2ll;
      ch1.insert(cv);
    } else {
      cv *= 2ll;
      cv++;
      ch1.insert(cv);
    }
  }
  long long cmn = 0;
  for (auto it = ch1.begin(); it != ch1.end();) {
    if (ch.find(*it) != ch.end() && *it > cmn) {
      auto it1 = it;
      it1++;
      ch.erase(ch.find(cmn));
      ch1.erase(ch1.find(cmn));
      cmn = *it;
      it = it1;
    } else
      it++;
  }
  for (auto it = ch1.begin(); it != ch1.end(); it++) {
    auto it1 = it;
    it1++;
    if (*it != 0 && it1 != ch1.end()) m[{*it, *it1}] += cost;
  }
  for (auto it = ch.begin(); it != ch.end(); it++) {
    auto it1 = it;
    it1++;
    if (*it != 0 && it1 != ch.end()) m[{*it, *it1}] += cost;
  }
}
long long ss(long long q, long long s) {
  long long cost = 0;
  long long cv = 0;
  long long qq[64], ss[64], ccv[64];
  for (long long i = 0; i < 64; i++) {
    qq[i] = q % 2;
    ss[i] = s % 2;
    ccv[i] = cv % 2;
    q /= 2, s /= 2, cv /= 2;
  }
  set<long long> ch;
  for (long long i = 63; i >= 0; i--) {
    if (qq[i] == 0) {
      cv *= 2ll;
      ch.insert(cv);
    } else {
      cv *= 2ll;
      cv++;
      ch.insert(cv);
    }
  }
  set<long long> ch1;
  cv = 0;
  for (long long i = 63; i >= 0; i--) {
    if (ss[i] == 0) {
      cv *= 2ll;
      ch1.insert(cv);
    } else {
      cv *= 2ll;
      cv++;
      ch1.insert(cv);
    }
  }
  long long cmn = 0;
  for (auto it = ch1.begin(); it != ch1.end();) {
    if (ch.find(*it) != ch.end() && *it > cmn) {
      auto it1 = it;
      it1++;
      ch.erase(ch.find(cmn));
      ch1.erase(ch1.find(cmn));
      cmn = *it;
      it = it1;
    } else
      it++;
  }
  for (auto it = ch1.begin(); it != ch1.end(); it++) {
    auto it1 = it;
    it1++;
    if (*it != 0 && it1 != ch1.end()) cost += m[{*it, *it1}];
  }
  for (auto it = ch.begin(); it != ch.end(); it++) {
    auto it1 = it;
    it1++;
    if (*it != 0 && it1 != ch.end()) cost += m[{*it, *it1}];
  }
  return cost;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long ch;
    cin >> ch;
    long long f, t, c = 0;
    if (ch == 1) {
      cin >> f >> t >> c;
      fs(f, t, c);
    } else {
      cin >> f >> t;
      cout << ss(f, t) << endl;
    }
  }
  return 0;
}
