#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, n, r, t, q, ch, u, v, w;
  unordered_map<long long, long long> mp;
  cin >> q;
  long long ans;
  while (q--) {
    cin >> ch;
    if (ch == 1) {
      cin >> u >> v >> w;
      set<long long> s1;
      set<long long> s2;
      set<long long>::iterator itr;
      vector<long long> path;
      while (u != 0) {
        s1.insert(u);
        u = u / 2;
      }
      while (v != 0) {
        s2.insert(v);
        v = v / 2;
      }
      itr = s1.end();
      itr--;
      for (;; itr--) {
        if (s2.find(*itr) != s2.end()) {
          r = (*itr);
          break;
        }
        s2.insert(*itr);
        if (itr == s1.begin()) break;
      }
      itr = s2.find(r);
      itr++;
      for (; itr != s2.end(); itr++) {
        path.push_back(*itr);
      }
      for (i = 0; i < path.size(); i++) {
        mp[path[i]] += w;
      }
    } else {
      cin >> u >> v;
      set<long long> s1;
      set<long long> s2;
      set<long long>::iterator itr;
      vector<long long> path;
      while (u != 0) {
        s1.insert(u);
        u = u / 2;
      }
      while (v != 0) {
        s2.insert(v);
        v = v / 2;
      }
      itr = s1.end();
      itr--;
      for (;; itr--) {
        if (s2.find(*itr) != s2.end()) {
          r = (*itr);
          break;
        }
        s2.insert(*itr);
        if (itr == s1.begin()) break;
      }
      itr = s2.find(r);
      itr++;
      for (; itr != s2.end(); itr++) {
        path.push_back(*itr);
      }
      ans = 0;
      for (i = 0; i < path.size(); i++) {
        ans += mp[path[i]];
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
