#include <bits/stdc++.h>
using namespace std;
int q;
map<long long, map<long long, long long>> mp;
int main() {
  cin >> q;
  while (q--) {
    int ch;
    cin >> ch;
    if (ch == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      set<long long> st;
      long long cx = u;
      while (cx) {
        st.insert(cx);
        cx = cx / 2;
      }
      cx = v;
      long long intr;
      while (cx) {
        if (st.find(cx) != st.end()) {
          intr = cx;
          break;
        }
        cx = cx / 2;
      }
      cx = u;
      while (cx != intr) {
        mp[cx][cx / 2] += w;
        mp[cx / 2][cx] += w;
        cx = cx / 2;
      }
      cx = v;
      while (cx != intr) {
        mp[cx][cx / 2] += w;
        mp[cx / 2][cx] += w;
        cx = cx / 2;
      }
    } else {
      long long u, v;
      cin >> u >> v;
      set<long long> st;
      long long cx = u;
      while (cx) {
        st.insert(cx);
        cx = cx / 2;
      }
      cx = v;
      long long intr;
      while (cx) {
        if (st.find(cx) != st.end()) {
          intr = cx;
          break;
        }
        cx = cx / 2;
      }
      long long sum = 0;
      cx = u;
      while (cx != intr) {
        sum += mp[cx][cx / 2];
        cx = cx / 2;
      }
      cx = v;
      while (cx != intr) {
        sum += mp[cx][cx / 2];
        cx = cx / 2;
      }
      cout << sum << endl;
    }
  }
}
