#include <bits/stdc++.h>
using namespace std;
long long lc(long long a, long long b) {
  while (a != b) {
    if (a < b) swap(a, b);
    a >>= 1;
  }
  return a;
}
map<pair<long long, char>, long long> ma;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int i, ty;
    long long a, b, w;
    scanf("%d", &ty);
    if (ty == 1) {
      scanf("%lld%lld", &a, &b);
      scanf("%lld", &w);
      long long an = lc(a, b);
      while (a != an) {
        if (a & 1)
          ma[make_pair(a / 2, 'r')] += w;
        else
          ma[make_pair(a / 2, 'l')] += w;
        a >>= 1;
      }
      while (b != an) {
        if (b & 1)
          ma[make_pair(b / 2, 'r')] += w;
        else
          ma[make_pair(b / 2, 'l')] += w;
        b >>= 1;
      }
    } else {
      scanf("%lld%lld", &a, &b);
      long long an = lc(a, b);
      long long p = 0;
      while (a != an) {
        if (a & 1) {
          __typeof(ma.begin()) it(ma.begin());
          it = ma.find(make_pair(a / 2, 'r'));
          if (it != ma.end()) p += it->second;
        } else {
          __typeof(ma.begin()) it(ma.begin());
          it = ma.find(make_pair(a / 2, 'l'));
          if (it != ma.end()) p += it->second;
        }
        a >>= 1;
      }
      while (b != an) {
        if (b & 1) {
          __typeof(ma.begin()) it(ma.begin());
          it = ma.find(make_pair(b / 2, 'r'));
          if (it != ma.end()) p += it->second;
        } else {
          __typeof(ma.begin()) it(ma.begin());
          it = ma.find(make_pair(b / 2, 'l'));
          if (it != ma.end()) p += it->second;
        }
        b >>= 1;
      }
      printf("%lld", p), printf("\n");
    }
  }
  return 0;
}
