#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long inf64 = 1ll * inf * inf;
bool solve() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  map<pair<long long, long long>, long long> cost;
  while (q--) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      long long u, v, w, p;
      cin >> u >> v >> w;
      while (u != v) {
        if (u > v) {
          p = u / 2;
          cost[make_pair(p, u)] += w;
          u = p;
        } else {
          p = v / 2;
          cost[make_pair(p, v)] += w;
          v = p;
        }
      }
    } else {
      long long u, v, p;
      cin >> u >> v;
      long long res = 0;
      while (u != v) {
        if (u > v) {
          p = u / 2;
          res += cost[make_pair(p, u)];
          u = p;
        } else {
          p = v / 2;
          res += cost[make_pair(p, v)];
          v = p;
        }
      }
      cout << res << '\n';
    }
  }
  return true;
}
int main() {
  solve();
  return 0;
}
