#include <bits/stdc++.h>
using namespace std;
const long long int N = 10e18;
map<long long, long long> mp;
int main() {
  int t;
  cin >> t;
  long long int type, u, v, w;
  while (t--) {
    scanf("%lld", &type);
    if (type == 1) {
      scanf("%lld%lld%lld", &u, &v, &w);
      while (u != v) {
        if (u > v)
          mp[u] += w, u /= 2;
        else
          mp[v] += w, v /= 2;
      }
    } else {
      scanf("%lld%lld", &u, &v);
      long long ans = 0;
      while (u != v) {
        if (u > v)
          ans += mp[u], u /= 2;
        else
          ans += mp[v], v /= 2;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
