#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long mod = 1000000007;
map<pair<long long, long long>, long long> mapp;
int lev(long long u) {
  int ret = 0;
  while (u != 0) {
    u /= 2;
    ret++;
  }
  return ret;
}
void solve() {
  int q;
  cin >> q;
  while (q--) {
    long long u, v, w;
    int typ;
    cin >> typ;
    if (typ == 1) {
      cin >> u >> v >> w;
      int k1 = lev(u), k2 = lev(v);
      while (k1 > k2) {
        mapp[pair<long long, long long>(u, u / 2)] += w;
        u /= 2;
        k1--;
      }
      while (k2 > k1) {
        mapp[pair<long long, long long>(v, v / 2)] += w;
        v /= 2;
        k2--;
      }
      while (u != v) {
        mapp[pair<long long, long long>(u, u / 2)] += w;
        mapp[pair<long long, long long>(v, v / 2)] += w;
        u /= 2;
        v /= 2;
      }
    } else {
      cin >> u >> v;
      long long ans = 0;
      int k1 = lev(u), k2 = lev(v);
      while (k1 > k2) {
        ans += mapp[pair<long long, long long>(u, u / 2)];
        u /= 2;
        k1--;
      }
      while (k2 > k1) {
        ans += mapp[pair<long long, long long>(v, v / 2)];
        v /= 2;
        k2--;
      }
      while (u != v) {
        ans += mapp[pair<long long, long long>(u, u / 2)];
        ans += mapp[pair<long long, long long>(v, v / 2)];
        u /= 2;
        v /= 2;
      }
      cout << ans << "\n";
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
