#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  ios::sync_with_stdio(0);
  cin >> q;
  int64_t v, u, w, temp, cost;
  map<pair<int64_t, int64_t>, int64_t> m;
  map<pair<int64_t, int64_t>, int64_t>::iterator it;
  while (q--) {
    cin >> temp;
    if (temp == 1) {
      cin >> v >> u >> w;
      while (v != u) {
        if (v > u) {
          it = m.find(make_pair(v / 2, v));
          if (it != m.end())
            it->second += w;
          else
            m[make_pair(v / 2, v)] = w;
          v /= 2;
        } else {
          it = m.find(make_pair(u / 2, u));
          if (it != m.end())
            it->second += w;
          else
            m[make_pair(u / 2, u)] = w;
          u /= 2;
        }
      }
    } else {
      cin >> v >> u;
      cost = 0;
      while (v != u) {
        if (v > u) {
          it = m.find(make_pair(v / 2, v));
          if (it != m.end()) cost += it->second;
          v /= 2;
        } else {
          it = m.find(make_pair(u / 2, u));
          if (it != m.end())
            cost += it->second;
          else
            m[make_pair(u / 2, u)] = 0;
          u /= 2;
        }
      }
      cout << cost << endl;
    }
  }
}
