#include <bits/stdc++.h>
using namespace std;
long long Q, q, f, t, v;
map<long long, long long> s;
long long LOG(long long x) {
  long long cnt = 0;
  while (x) {
    cnt++;
    x >>= 1;
  }
  return cnt;
}
int main() {
  scanf("%I64d", &Q);
  while (Q--) {
    scanf("%I64d", &q);
    switch (q) {
      case 1:
        scanf("%I64d %I64d %I64d", &f, &t, &v);
        if (LOG(f) < LOG(t)) swap(f, t);
        while (LOG(f) > LOG(t)) {
          s[f] += v;
          f >>= 1;
        }
        while (f != t) {
          s[f] += v;
          s[t] += v;
          f >>= 1;
          t >>= 1;
        }
        break;
      case 2:
        scanf("%I64d %I64d", &f, &t);
        long long l = 0, r = 0;
        long long ans = 0;
        if (LOG(f) < LOG(t)) swap(f, t);
        while (LOG(f) > LOG(t)) {
          l += s[f];
          f >>= 1;
        }
        while (f != t) {
          l += s[f];
          f >>= 1;
          r += s[t];
          t >>= 1;
        }
        printf("%I64d\n", l + r);
        break;
    }
  }
  return 0;
}
