#include <bits/stdc++.h>
using namespace std;
int popcnt(long long x) {
  int cnt = 0;
  while (x) {
    x /= 2;
    ++cnt;
  }
  return cnt;
}
void normalize(long long& a, long long& b) {
  if (popcnt(a) > popcnt(b)) {
    normalize(b, a);
  } else {
    while (popcnt(b) > popcnt(a)) b /= 2;
  }
}
long long getlca(long long a, long long b) {
  normalize(a, b);
  while (a != b) {
    a /= 2;
    b /= 2;
  }
  return a;
}
map<long long, long long> segs;
int main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    long long t, a, b;
    cin >> t >> a >> b;
    long long par = getlca(a, b);
    if (t == 1) {
      int c;
      cin >> c;
      while (a != par) {
        segs[a] += c;
        a /= 2;
      }
      while (b != par) {
        segs[b] += c;
        b /= 2;
      }
    } else {
      long long cost = 0;
      while (a != par) {
        cost += segs[a];
        a /= 2;
      }
      while (b != par) {
        cost += segs[b];
        b /= 2;
      }
      cout << cost << '\n';
    }
  }
  return 0;
}
