#include <bits/stdc++.h>
using namespace std;
long long level(long long n) {
  long long z = log2(n);
  z++;
  return z;
}
void solve() {
  long long q;
  cin >> q;
  map<pair<long long, long long>, long long> dist;
  while (q--) {
    long long tp;
    cin >> tp;
    if (tp == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      long long x = u;
      long long y = v;
      while (level(u) > level(v)) {
        u /= 2;
      }
      while (level(u) < level(v)) {
        v /= 2;
      }
      long long lca;
      while (u != v) {
        while (level(u) > level(v)) {
          u /= 2;
        }
        while (level(u) < level(v)) {
          v /= 2;
        }
        u /= 2;
        v /= 2;
      }
      lca = u;
      while (y > lca) {
        dist[{y, y / 2}] += w;
        y /= 2;
      }
      while (x > lca) {
        dist[{x, x / 2}] += w;
        x /= 2;
      }
    } else {
      long long u, v;
      cin >> u >> v;
      long long ans = 0;
      long long x = u;
      long long y = v;
      while (level(u) > level(v)) {
        u /= 2;
      }
      while (level(u) < level(v)) {
        v /= 2;
      }
      long long lca;
      while (u != v) {
        while (level(u) > level(v)) {
          u /= 2;
        }
        while (level(u) < level(v)) {
          v /= 2;
        }
        u /= 2;
        v /= 2;
      }
      lca = u;
      while (y > lca) {
        ans += dist[{y, y / 2}];
        y /= 2;
      }
      while (x > lca) {
        ans += dist[{x, x / 2}];
        x /= 2;
      }
      cout << ans << endl;
    }
  }
}
int main() { solve(); }
