#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * int(1e9);
const long long INFll = 1ll * int(1e9) * int(1e9);
const int MOD = 1000000007;
template <typename T>
ostream& operator<<(ostream& out, pair<T, T>& a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T>
istream& operator>>(istream& in, pair<T, T>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<pair<T, T> > a) {
  for (int i = 0; i < a.size(); ++i) out << a[i] << endl;
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) in >> a[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> a) {
  for (int i = 0; i < a.size(); ++i)
    if (i == a.size() - 1)
      out << a[i];
    else
      out << a[i] << " ";
  return out;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int q;
  cin >> q;
  map<long long, long long> cost;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      long long v, u, w;
      cin >> u >> v >> w;
      while (u != v) {
        if (u > v) {
          cost[u] += w;
          u >>= 1;
        } else {
          cost[v] += w;
          v >>= 1;
        }
      }
    } else {
      long long v, u;
      cin >> v >> u;
      long long ans = 0;
      while (u != v) {
        if (u > v) {
          ans += cost[u];
          u >>= 1;
        } else {
          ans += cost[v];
          v >>= 1;
        }
      }
      cout << ans << endl;
    }
  }
  if (0)
    cerr << fixed << setprecision(0)
         << "TIME = " << clock() / (long double)CLOCKS_PER_SEC * 1000 << "\n";
  return 0;
}
