#include <bits/stdc++.h>
using namespace std;
map<long long, long long> road;
vector<long long> buff;
int hightbit(long long x) {
  x = abs(x);
  int ans = 0;
  while (x && (x >>= 1)) ans++;
  return ans;
}
void ro_sta(long long a, long long b) {
  buff.clear();
  if (a > b) swap(a, b);
  long long d = hightbit(b) - hightbit(a);
  for (int i = 0; i < d; i++) {
    buff.push_back(b);
    b >>= 1;
  }
  while (a != b) {
    buff.push_back(a);
    buff.push_back(b);
    a >>= 1;
    b >>= 1;
  }
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  long long q;
  cin >> q;
  long long cmd, u, v, w;
  while (q--) {
    cin >> cmd;
    if (cmd == 1) {
      cin >> v >> u >> w;
      ro_sta(v, u);
      for (int i = 0; i < buff.size(); i++) {
        road[buff[i]] += w;
      }
    } else {
      cin >> v >> u;
      ro_sta(v, u);
      long long sum = 0;
      for (int i = 0; i < buff.size(); i++) {
        sum += road[buff[i]];
      }
      cout << sum << endl;
    }
  }
  return 0;
}
