#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cost;
long long w, ans;
int level(long long x) {
  int ans = 0;
  while (x != 0) {
    x /= 2;
    ans++;
  }
  return ans;
}
void visit(long long x, int type) {
  if (type == 1)
    cost[x] += w;
  else
    ans += cost[x];
}
void route(long long u, long long v, int type) {
  while (level(u) > level(v)) {
    visit(u, type);
    u /= 2;
  }
  while (level(u) < level(v)) {
    visit(v, type);
    v /= 2;
  }
  while (u != v) {
    visit(u, type);
    visit(v, type);
    u /= 2;
    v /= 2;
  }
}
int main() {
  int q, t, i;
  long long u, v;
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> t >> u >> v;
    if (t == 1) {
      cin >> w;
      route(u, v, 1);
    } else {
      ans = 0;
      route(u, v, 2);
      cout << ans << "\n";
    }
  }
  return 0;
}
