#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mm[2];
void solve(long long a, long long b, int w) {
  while (b != a) {
    if (b > a) {
      if (b % 2 == 0) {
        mm[0][b / 2] += w;
      } else
        mm[1][b / 2] += w;
      b = b / 2;
    } else
      swap(a, b);
  }
}
long long get(long long a, long long b) {
  long long s = 0;
  while (b != a) {
    if (b > a) {
      if (b % 2 == 0) {
        s += mm[0][b / 2];
      } else
        s += mm[1][b / 2];
      b = b / 2;
    } else
      swap(a, b);
  }
  return s;
}
int main() {
  int n;
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    if (p == 1) {
      long long x, y;
      int w;
      cin >> x >> y >> w;
      solve(x, y, w);
    } else {
      long long x, y;
      cin >> x >> y;
      cout << get(x, y) << endl;
    }
  }
}
