#include <bits/stdc++.h>
using namespace std;
int q;
map<long long, long long> f;
long long lca(long long u, long long v, long long w) {
  long long ret = 0;
  while (u != v) {
    if (u < v) swap(u, v);
    f[u] = f[u] + w;
    ret += f[u];
    u >>= 1;
  }
  return ret;
}
int main() {
  scanf("%d", &q);
  int cmd;
  while (q--) {
    long long u, v, w;
    scanf("%d", &cmd);
    if (cmd == 1) {
      cin >> u >> v >> w;
      lca(u, v, w);
    } else {
      cin >> u >> v;
      cout << lca(u, v, 0) << endl;
    }
  }
  return 0;
}
