#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  map<array<long long, 2>, long long> cost;
  long long q;
  cin >> q;
  while (q--) {
    long long tp;
    cin >> tp;
    if (tp == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      vector<long long> au, av;
      while (u != 0) {
        au.push_back(u);
        u /= 2;
      }
      while (v != 0) {
        av.push_back(v);
        v /= 2;
      }
      long long idu = 0, idv = 0;
      for (long long i = 0; i < au.size(); ++i) {
        bool found = 0;
        for (long long j = 0; j < av.size(); ++j) {
          if (av[j] == au[i]) {
            idv = j;
            idu = i;
            found = 1;
            break;
          }
        }
        if (found) break;
      }
      for (long long i = 1; i <= idu; ++i) {
        cost[{au[i], au[i - 1]}] += w;
      }
      for (long long i = 1; i <= idv; ++i) {
        cost[{av[i], av[i - 1]}] += w;
      }
    } else {
      long long u, v;
      cin >> u >> v;
      vector<long long> au, av;
      while (u != 0) {
        au.push_back(u);
        u /= 2;
      }
      while (v != 0) {
        av.push_back(v);
        v /= 2;
      }
      long long idu = 0, idv = 0;
      for (long long i = 0; i < au.size(); ++i) {
        bool found = 0;
        for (long long j = 0; j < av.size(); ++j) {
          if (av[j] == au[i]) {
            idv = j;
            idu = i;
            found = 1;
            break;
          }
        }
        if (found) break;
      }
      long long res = 0;
      for (long long i = 1; i <= idu; ++i) {
        res += cost[{au[i], au[i - 1]}];
      }
      for (long long i = 1; i <= idv; ++i) {
        res += cost[{av[i], av[i - 1]}];
      }
      cout << res << "\n";
    }
  }
}
