#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, v, u, w, i, j;
  long long int a, b;
  cin >> q;
  map<pair<long long int, long long int>, long long int> ans;
  while (q--) {
    long long int x;
    cin >> x;
    if (x == 1) {
      cin >> v >> u >> w;
      a = max(u, v);
      b = min(u, v);
      while (1) {
        if (a / 2 == b) {
          ans[make_pair(a, a / 2)] += w;
          ans[make_pair(a / 2, a)] += w;
          break;
        }
        if (2 * a == b) {
          ans[make_pair(a, 2 * a)] += w;
          ans[make_pair(2 * a, a)] += w;
          break;
        }
        if (2 * a + 1 == b) {
          ans[make_pair(a, 2 * a + 1)] += w;
          ans[make_pair(2 * a + 1, a)] += w;
          break;
        }
        ans[make_pair(a, a / 2)] += w;
        a = a / 2;
        if (b > a) {
          swap(a, b);
        }
      }
    } else {
      cin >> u >> v;
      a = max(u, v);
      b = min(u, v);
      long long int ans2 = 0;
      while (1) {
        if (a / 2 == b) {
          ans2 += ans[make_pair(a, a / 2)];
          break;
        }
        if (2 * a == b) {
          ans2 += ans[make_pair(a, 2 * a)];
          break;
        }
        if (2 * a + 1 == b) {
          ans2 += ans[make_pair(a, 2 * a + 1)];
          break;
        }
        ans2 += ans[make_pair(a, a / 2)];
        a = a / 2;
        if (b > a / 2) swap(a, b);
      }
      cout << ans2 << endl;
    }
  }
}
