#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<vector<ll>, vector<ll>> fn(ll u, ll v) {
  vector<ll> p1, p2;
  while (u >= 1) {
    p1.push_back(u);
    u /= 2;
  }
  while (v >= 1) {
    p2.push_back(v);
    v /= 2;
  }
  while (p1.size() > 0 && p2.size() > 0 &&
         (p1[p1.size() - 1] == p2[p2.size() - 1])) {
    p1.pop_back();
    p2.pop_back();
  }
  return {p1, p2};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  unordered_map<ll, ll> mp;
  while (n--) {
    ll t, u, v, w;
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      auto [p1, p2] = fn(u, v);
      for (auto i : p1) {
        if (mp.find(i) == mp.end())
          mp[i] = w;
        else
          mp[i] += w;
      }
      for (auto i : p2) {
        if (mp.find(i) == mp.end())
          mp[i] = w;
        else
          mp[i] += w;
      }
    } else {
      cin >> u >> v;
      auto [p1, p2] = fn(u, v);
      ll count = 0;
      for (auto i : p1)
        if (mp.find(i) != mp.end()) count += mp[i];
      for (auto i : p2)
        if (mp.find(i) != mp.end()) count += mp[i];
      cout << count << endl;
    }
  }
  return 0;
}
