#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  long long s, u, v, w;
  map<pair<long long, long long>, long long> mp;
  vector<long long> vec1, vec2;
  long long ans = 0;
  while (q--) {
    cin >> s;
    if (s == 1) {
      cin >> u >> v >> w;
      vec1.clear();
      vec2.clear();
      while (u / 2) {
        vec1.push_back(u);
        u /= 2;
      }
      vec1.push_back(u);
      while (v) {
        if (find(vec1.begin(), vec1.end(), v) == vec1.end()) {
          vec2.push_back(v);
          mp[{v, v / 2}] += w;
          v /= 2;
        } else {
          break;
        }
      }
      int pos = find(vec1.begin(), vec1.end(), v) - vec1.begin();
      for (int i = vec2.size() - 1; i >= 1; i--) {
        mp[{vec2[i], vec2[i - 1]}] += w;
      }
      for (int i = pos; i >= 1; i--) {
        mp[{vec1[i], vec1[i - 1]}] += w;
      }
      for (int i = 0; i < pos; i++) {
        mp[{vec1[i], vec1[i + 1]}] += w;
      }
    } else {
      cin >> u >> v;
      ans = 0;
      vec1.clear();
      vec2.clear();
      while (u / 2) {
        vec1.push_back(u);
        u /= 2;
      }
      vec1.push_back(u);
      while (v) {
        if (find(vec1.begin(), vec1.end(), v) == vec1.end()) {
          vec2.push_back(v);
          if (mp.find({v, v / 2}) != mp.end()) {
            ans += mp[{v, v / 2}];
          }
          v /= 2;
        } else {
          break;
        }
      }
      int pos = find(vec1.begin(), vec1.end(), v) - vec1.begin();
      for (int i = 0; i < pos; i++) {
        if (mp.find({vec1[i], vec1[i + 1]}) != mp.end())
          ans += mp[{vec1[i], vec1[i + 1]}];
      }
      cout << ans << endl;
    }
  }
  return 0;
}
