#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
inline void write(int k) {
  char ch[(int)log10(k) + 1];
  int num = 0;
  while (k) ch[++num] = k % 10, k /= 10;
  while (num) putchar(ch[num--] + '0');
  putchar('\n');
}
int q;
map<long long, long long> data;
long long t1, t2, t3;
long long func(long long s, long long t, long long m) {
  long long out = 0;
  while (s != t)
    if (s > t)
      out += data[s] += m, s >>= 1;
    else
      out += data[t] += m, t >>= 1;
  return out;
}
int main() {
  q = read();
  while (q--)
    if (read() == 1)
      t1 = read(), t2 = read(), t3 = read(), func(t1, t2, t3);
    else
      printf("%I64d\n", func(read(), read(), 0));
  return 0;
}
