#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
long long n;
map<long long, long long> M;
inline bool pd(long long u, long long v) {
  while (v) {
    if (v == u) return 1;
    v /= 2;
  }
  return 0;
}
int main() {
  n = read();
  for (long long i = 1; i <= n; i++) {
    long long s1 = read();
    if (s1 == 1) {
      long long s2 = read(), s3 = read(), s4 = read();
      for (long long i = s2; pd(i, s3) == 0; i >>= 1) {
        M[i] += s4;
      }
      for (long long i = s3; pd(i, s2) == 0; i >>= 1) {
        M[i] += s4;
      }
    } else {
      long long s2 = read(), s3 = read(), ans = 0;
      for (long long i = s2; pd(i, s3) == 0; i >>= 1) {
        ans += M[i];
      }
      for (long long i = s3; pd(i, s2) == 0; i >>= 1) {
        ans += M[i];
      }
      writeln(ans);
    }
  }
}
