#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mp;
void up(long long u, long long v, long long w) {
  if (u == v) {
    return;
  }
  if (u > v) {
    mp[make_pair(u, u / 2)] += w;
    up(u / 2, v, w);
  } else {
    mp[make_pair(v, v / 2)] += w;
    up(u, v / 2, w);
  }
}
long long ans;
void q(long long u, long long v) {
  if (u == v) {
    return;
  }
  if (u > v) {
    ans += mp[make_pair(u, u / 2)];
    q(u / 2, v);
  } else {
    ans += mp[make_pair(v, v / 2)];
    q(u, v / 2);
  }
}
int main() {
  int qr, tp;
  scanf("%d", &qr);
  long long u, v, w;
  while (qr--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%lld %lld %lld", &u, &v, &w);
      up(u, v, w);
    } else {
      ans = 0;
      scanf("%lld %lld", &u, &v);
      q(u, v);
      printf("%I64d\n", ans);
    }
  }
}
