#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long LCA(long long a, long long b) {
  set<long long> seen;
  while (a > 0) {
    seen.insert(a);
    a /= 2;
  }
  while (b > 0) {
    if (seen.find(b) != seen.end()) return b;
    b /= 2;
  }
  assert(0);
  return -1;
}
map<long long, long long> cost;
int main() {
  ios_base::sync_with_stdio(0);
  int q;
  cin >> q;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      long long lca = LCA(u, v);
      while (u != lca) {
        cost[u] += w;
        u /= 2;
      }
      while (v != lca) {
        cost[v] += w;
        v /= 2;
      }
    } else {
      long long u, v;
      cin >> u >> v;
      long long lca = LCA(u, v);
      long long ans = 0;
      while (u != lca) {
        ans += cost[u];
        u /= 2;
      }
      while (v != lca) {
        ans += cost[v];
        v /= 2;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
