#include <bits/stdc++.h>
using namespace std;
int t, q;
long long u, v, w;
map<long long, long long> mp;
long long dfs(long long u, long long v, long long w) {
  long long ans = 0;
  for (; u != v;) {
    if (u < v) swap(u, v);
    mp[u] += w, ans += mp[u], u >>= 1;
  }
  return ans;
}
int main() {
  for (scanf("%d", &q); q--;) {
    scanf("%d%lld%lld", &t, &u, &v);
    if (t == 1)
      scanf("%lld", &w), dfs(u, v, w);
    else
      printf("%lld\n", dfs(u, v, 0));
  }
}
