#include <bits/stdc++.h>
using namespace std;
int q;
map<long long, long long> mp;
long long lca(long long u, long long v, long long c = 0) {
  long long res = 0;
  while (u != v) {
    if (u > v) swap(u, v);
    if (mp.find(v) != mp.end()) res += mp[v];
    if (c != 0) mp[v] += c;
    v /= 2;
  }
  return res;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      long long u, v, c;
      scanf("%lld%lld%lld", &u, &v, &c);
      lca(u, v, c);
    } else {
      long long u, v;
      scanf("%lld%lld", &u, &v);
      printf("%lld\n", lca(u, v));
    }
  }
  return 0;
}
