#include <bits/stdc++.h>
using namespace std;
long long n, ch, x, y, z, a[111], sz1, b[111], sz2, ans;
map<long long, long long> v;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &ch);
    if (ch == 1) {
      scanf("%lld%lld%lld", &x, &y, &z);
      sz1 = sz2 = 0;
      while (x > 1) {
        a[++sz1] = x;
        x /= 2;
      }
      while (y > 1) {
        b[++sz2] = y;
        y /= 2;
      }
      reverse(a + 1, a + sz1 + 1);
      reverse(b + 1, b + sz2 + 1);
      long long p = 1;
      for (long long j = 1; a[j] == b[j] && j <= min(sz1, sz2); j++, p++)
        ;
      for (long long j = p; j <= sz1; j++) v[a[j]] += z;
      for (long long j = p; j <= sz2; j++) v[b[j]] += z;
    } else {
      scanf("%lld%lld", &x, &y);
      ans = 0;
      sz1 = sz2 = 0;
      while (x > 1) {
        a[++sz1] = x;
        x /= 2;
      }
      while (y > 1) {
        b[++sz2] = y;
        y /= 2;
      }
      reverse(a + 1, a + sz1 + 1);
      reverse(b + 1, b + sz2 + 1);
      long long p = 1;
      for (long long j = 1; a[j] == b[j] && j <= min(sz1, sz2); j++, p++)
        ;
      for (long long j = p; j <= sz1; j++) ans += v[a[j]];
      for (long long j = p; j <= sz2; j++) ans += v[b[j]];
      printf("%lld\n", ans);
    }
  }
}
