#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> m;
map<pair<long long, long long>, long long>::iterator mit;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      long long v, u, w;
      cin >> v >> u >> w;
      long long vt = v;
      set<long long> s;
      set<long long>::iterator it;
      while (vt != 0) {
        s.insert(vt);
        vt /= 2;
      }
      bool flag = true;
      long long ut = u;
      while (flag) {
        if ((it = s.find(ut)) != s.end()) {
          break;
        }
        ut /= 2;
      }
      long long parent = *it;
      vt = v;
      set<pair<long long, long long> > sp;
      while (vt != parent) {
        long long tmp = 0;
        if ((mit = m.find(make_pair(vt, vt / 2))) != m.end()) {
          tmp = (*mit).second;
          m[make_pair(vt, vt / 2)] = tmp + w;
        }
        m.insert(make_pair(make_pair(vt, vt / 2), tmp + w));
        vt /= 2;
      }
      ut = u;
      while (ut != parent) {
        long long tmp = 0;
        if ((mit = m.find(make_pair(ut, ut / 2))) != m.end()) {
          tmp = (*mit).second;
          m[make_pair(ut, ut / 2)] = tmp + w;
        }
        m.insert(make_pair(make_pair(ut, ut / 2), tmp + w));
        ut /= 2;
      }
    } else {
      long long v, u;
      cin >> v >> u;
      long long vt = v;
      set<long long> s;
      set<long long>::iterator it;
      while (vt != 0) {
        s.insert(vt);
        vt /= 2;
      }
      bool flag = true;
      long long ut = u;
      while (flag) {
        if ((it = s.find(ut)) != s.end()) {
          break;
        }
        ut /= 2;
      }
      long long parent = *it;
      long long cost = 0;
      vt = v;
      while (vt != parent) {
        long long tmp = 0;
        if ((mit = m.find(make_pair(vt, vt / 2))) != m.end()) {
          tmp = (*mit).second;
        }
        cost += tmp;
        vt /= 2;
      }
      ut = u;
      while (ut != parent) {
        long long tmp = 0;
        if ((mit = m.find(make_pair(ut, ut / 2))) != m.end()) {
          tmp = (*mit).second;
        }
        cost += tmp;
        ut /= 2;
      }
      cout << cost << endl;
    }
  }
}
