#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = (double)1e-8;
const int mod = (int)1000000007;
const int maxn = (int)1e5 + 5;
set<long long> q;
map<long long, long long> m;
int T;
long long x, y, z, typ, p, v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> T;
  while (T--) {
    cin >> typ;
    q.clear();
    if (typ == 1) {
      cin >> x >> y >> z;
      p = 0;
      v = x;
      while (v != 0) {
        q.insert(v);
        v /= 2;
      }
      v = y;
      p = v;
      while (!q.count(v)) {
        v /= 2;
        p = v;
      }
      v = x;
      while (v != p) {
        m[v] += z;
        v /= 2;
      }
      v = y;
      while (v != p) {
        m[v] += z;
        v /= 2;
      }
    } else {
      z = 0;
      cin >> x >> y;
      p = 0;
      v = x;
      while (v != 0) {
        q.insert(v);
        v /= 2;
      }
      v = y;
      p = v;
      while (!q.count(v)) {
        v /= 2;
        p = v;
      }
      v = x;
      while (v != p) {
        z += m[v];
        v /= 2;
      }
      v = y;
      while (v != p) {
        z += m[v];
        v /= 2;
      }
      cout << z << "\n";
    }
  }
  return 0;
}
