#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mp;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int comm;
    long long u, v, w;
    scanf("%d", &comm);
    if (comm == 1) {
      cin >> u >> v >> w;
      while (u != v) {
        pair<long long, long long> p;
        if (u > v) {
          p.first = u / 2;
          p.second = u;
          mp[p] += w;
          u = u / 2;
        } else {
          p.first = v / 2;
          p.second = v;
          mp[p] += w;
          v = v / 2;
        }
      }
    } else {
      cin >> u >> v;
      long long ans = 0;
      while (u != v) {
        pair<long long, long long> p;
        if (u > v) {
          p.first = u / 2;
          p.second = u;
          ans += mp[p];
          u = u / 2;
        } else {
          p.first = v / 2;
          p.second = v;
          ans += mp[p];
          v = v / 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
