#include <bits/stdc++.h>
using namespace std;
map<long long, long long> Map;
void modify(long long x, long long y) {
  map<long long, long long>::iterator it;
  long long c;
  scanf("%I64d", &c);
  while (x != y) {
    if (x < y) swap(x, y);
    it = Map.find(x);
    if (it != Map.end())
      it->second += c;
    else
      Map[x] = c;
    x >>= 1;
  }
}
long long query(long long x, long long y) {
  map<long long, long long>::iterator it;
  long long ans = 0;
  while (x != y) {
    if (x < y) swap(x, y);
    it = Map.find(x);
    if (it != Map.end()) ans += it->second;
    x >>= 1;
  }
  return ans;
}
int main(int argc, char* argv[]) {
  int q = 0;
  for (; scanf("%d", &q) != EOF;) {
    Map.clear();
    while (q--) {
      int od;
      long long x, y, c;
      scanf("%d%I64d%I64d", &od, &x, &y);
      if (od == 1)
        modify(x, y);
      else
        printf("%I64d\n", query(x, y));
    }
  }
  return 0;
}
