#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
void lcaIncrease(long long y, long long z, long long a) {
  while (y != z) {
    if (y > z) {
      m[y] += a;
      y /= 2;
    } else if (z > y) {
      m[z] += a;
      z /= 2;
    }
  }
}
unsigned long long lcaGet(long long y, long long z) {
  unsigned long long result = 0;
  while (y != z) {
    if (y > z) {
      result += m[y];
      y /= 2;
    } else if (z > y) {
      result += m[z];
      z /= 2;
    }
  }
  return result;
}
int main() {
  int k;
  cin >> k;
  for (int counter = 0; counter < k; counter++) {
    long long x, y, z;
    cin >> x >> y >> z;
    if (x == 1) {
      long long a;
      cin >> a;
      lcaIncrease(y, z, a);
    } else {
      unsigned long long result = lcaGet(y, z);
      cout << result << endl;
    }
  }
  return 0;
}
