#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> edges;
void inc_w(long long v, long long u, long long w) {
  while (v != u) {
    if (v > u) {
      edges[make_pair(v, v / 2)] += w;
      edges[make_pair(v / 2, v)] += w;
      v /= 2;
    } else {
      edges[make_pair(u, u / 2)] += w;
      edges[make_pair(u / 2, u)] += w;
      u /= 2;
    }
  }
}
long long calc_path(long long v, long long u) {
  long long val = 0;
  while (v != u) {
    if (v > u) {
      val += edges[make_pair(v, v / 2)];
      v /= 2;
    } else {
      val += edges[make_pair(u, u / 2)];
      u /= 2;
    }
  }
  return val;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    long long v, u, w;
    if (a == 1) {
      cin >> v >> u >> w;
      inc_w(v, u, w);
    } else {
      cin >> v >> u;
      cout << calc_path(v, u) << endl;
    }
  }
  return 0;
}
