#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-9;
const int mod = 1000000007;
map<long long, long long> mymap;
long long ans;
long long higbit(long long i) {
  int l = 0;
  while (i >>= 1) {
    ++l;
  }
  return l;
}
void build(long long a, int ah, long long b, int bh, long long w) {
  if (ah > bh)
    mymap[a] += w, build(a >> 1, ah - 1, b, bh, w);
  else if (ah < bh)
    mymap[b] += w, build(a, ah, b >> 1, bh - 1, w);
  else if (ah == bh && a != b)
    mymap[a] += w, build(a >> 1, ah - 1, b, bh, w);
}
void res(long long a, int ah, long long b, int bh) {
  if (ah > bh)
    ans += mymap[a], res(a >> 1, ah - 1, b, bh);
  else if (ah < bh)
    ans += mymap[b], res(a, ah, b >> 1, bh - 1);
  else if (ah == bh && a != b)
    ans += mymap[a], res(a >> 1, ah - 1, b, bh);
}
int main() {
  int q;
  long long a, b, c, d;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a;
    if (a == 1) {
      cin >> b >> c >> d;
      build(b, higbit(b), c, higbit(c), d);
    } else {
      cin >> b >> c;
      ans = 0;
      res(b, higbit(b), c, higbit(c));
      cout << ans << "\n";
    }
  }
}
