#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cache;
int main() {
  int q;
  int a;
  long long v, u;
  long long w;
  cin >> q;
  while (q--) {
    cin >> a;
    if (a == 1) {
      cin >> v >> u >> w;
      while (1) {
        if (v == u) break;
        if (v < u) {
          long long tm;
          tm = v;
          v = u;
          u = tm;
        }
        if (v % 2 == 0) {
          if (cache.find(v) != cache.end())
            cache[v] += w;
          else
            cache[v] = w;
          v = v / 2;
        } else {
          if (cache.find(v) != cache.end())
            cache[v] += w;
          else
            cache[v] = w;
          v = (v - 1) / 2;
        }
      }
    } else {
      cin >> v >> u;
      long long fee = 0;
      while (1) {
        if (v == u) break;
        if (v < u) {
          long long tm;
          tm = v;
          v = u;
          u = tm;
        }
        if (cache.find(v) != cache.end()) fee += cache[v];
        v = v / 2;
      }
      cout << fee << endl;
    }
  }
  return 0;
}
