#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mp;
int main() {
  long long n, m, i, j, k, c = 0, x, y, z;
  cin >> n;
  while (n--) {
    cin >> x >> y >> z;
    if (x == 1) {
      cin >> m;
      while (y != z) {
        if (y > z) {
          mp[make_pair(y, y / 2)] += m;
          y = y / 2;
        } else {
          mp[make_pair(z, z / 2)] += m;
          z = z / 2;
        }
      }
    } else {
      long long s = 0;
      while (y != z) {
        if (y > z) {
          s += mp[make_pair(y, y / 2)];
          y = y / 2;
        } else {
          s += mp[make_pair(z, z / 2)];
          z = z / 2;
        }
      }
      cout << s << "\n";
    }
  }
}
