#include <bits/stdc++.h>
using namespace std;
map<long long, long long> zz;
map<long long, long long>::iterator bb;
long long aa[70];
int main() {
  int t, a;
  long long c = 1e18 + 1;
  aa[0] = 1;
  for (long long i = 1;; i++) {
    aa[i] = aa[i - 1] << 1;
    if (aa[i] > c) break;
  }
  cin >> t;
  while (t--) {
    cin >> a;
    if (a == 1) {
      long long v, u, w;
      cin >> v >> u >> w;
      int i;
      for (i = 0;; i++)
        if (v < aa[i] || u < aa[i]) break;
      while (v >= aa[i]) {
        zz[v] = zz[v] + w;
        v /= 2;
      }
      while (u >= aa[i]) {
        zz[u] += w;
        u /= 2;
      }
      while (v != u) {
        zz[v] += w;
        v /= 2;
        zz[u] += w;
        u /= 2;
      }
    }
    if (a == 2) {
      long long u, v, s = 0;
      cin >> u >> v;
      int i;
      for (i = 0;; i++)
        if (v < aa[i] || u < aa[i]) break;
      while (v >= aa[i]) {
        s += zz[v];
        v /= 2;
      }
      while (u >= aa[i]) {
        s += zz[u];
        u /= 2;
      }
      while (u != v) {
        s += zz[u];
        u /= 2;
        s += zz[v];
        v /= 2;
      }
      cout << s << endl;
    }
  }
  return 0;
}
