#include <bits/stdc++.h>
using namespace std;
const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9, base = 1e9 + 7;
const long long ool = 1e18 + 9;
int n;
map<long long, long long> a[3];
long long getp(long long v, long long u) {
  vector<long long> vec1, vec2;
  while (v > 0) {
    vec1.push_back(v);
    v /= 2ll;
  }
  while (u > 0) {
    vec2.push_back(u);
    u /= 2ll;
  }
  reverse(vec1.begin(), vec1.end());
  reverse(vec2.begin(), vec2.end());
  for (long long i = 0; i <= min((int)vec1.size(), (int)vec2.size()) - 1; ++i) {
    if (vec1[i] != vec2[i]) {
      return vec1[i - 1];
    }
  }
  return vec1[min((int)vec1.size(), (int)vec2.size()) - 1];
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    int qt;
    long long v, u;
    cin >> qt >> v >> u;
    long long par = getp(v, u);
    if (qt == 1) {
      long long cost;
      cin >> cost;
      while (v != par) {
        bool ok = (v & 1);
        v /= 2;
        a[ok][v] += cost;
      }
      while (u != par) {
        bool ok = (u & 1);
        u /= 2;
        a[ok][u] += cost;
      }
    } else {
      long long res = 0;
      while (v != par) {
        bool ok = (v & 1);
        v /= 2;
        res += a[ok][v];
      }
      while (u != par) {
        bool ok = (u & 1);
        u /= 2;
        res += a[ok][u];
      }
      cout << res << "\n";
    }
  }
  return 0;
}
