#include <bits/stdc++.h>
using namespace std;
int q;
map<pair<unsigned long long, unsigned long long>, unsigned long long> edges,
    tmpMap;
set<pair<unsigned long long, unsigned long long> > tmpSet;
int main() {
  cin >> q;
  for (int i = 0, _a = (q); i < _a; ++i) {
    int t;
    unsigned long long u, v, w;
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      tmpMap.clear();
      while (u != 1) {
        tmpMap[make_pair(u >> 1, u)] = w;
        u >>= 1;
      }
      while (v != 1) {
        pair<unsigned long long, unsigned long long> e = make_pair(v >> 1, v);
        if (tmpMap.count(e) != 0)
          tmpMap.erase(e);
        else
          tmpMap[e] = w;
        v >>= 1;
      }
      for (__typeof((tmpMap).begin()) it = (tmpMap).begin();
           it != (tmpMap).end(); it++)
        edges[(*it).first] += (*it).second;
    } else {
      cin >> u >> v;
      tmpSet.clear();
      while (u != 1) {
        tmpSet.insert(make_pair(u >> 1, u));
        u >>= 1;
      }
      while (v != 1) {
        pair<unsigned long long, unsigned long long> e = make_pair(v >> 1, v);
        if (tmpSet.count(e) != 0)
          tmpSet.erase(e);
        else
          tmpSet.insert(e);
        v >>= 1;
      }
      unsigned long long ans = 0;
      for (__typeof((tmpSet).begin()) it = (tmpSet).begin();
           it != (tmpSet).end(); it++)
        ans += edges[(*it)];
      cout << ans << '\n';
    }
  }
  return 0;
}
