#include <bits/stdc++.h>
using namespace std;
const int me = 100025;
int q, type;
long long u, v, w;
map<pair<long long, long long>, long long> cost;
vector<pair<long long, long long> > get_path(long long u, long long v) {
  vector<pair<long long, long long> > p;
  while (u != v) {
    if (u > v) {
      p.push_back(make_pair(u / 2, u));
      u /= 2;
    } else {
      p.push_back(make_pair(v / 2, v));
      v /= 2;
    }
  }
  return p;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> u >> v >> w;
      vector<pair<long long, long long> > p = get_path(u, v);
      for (auto i : p) {
        if (!cost.count(i))
          cost[i] = w;
        else
          cost[i] += w;
      }
    } else {
      cin >> u >> v;
      vector<pair<long long, long long> > p = get_path(u, v);
      long long s = 0;
      for (pair<long long, long long> i : p) {
        if (cost.count(i)) s += cost[i];
      }
      cout << s << endl;
    }
  }
  return 0;
}
