#include <bits/stdc++.h>
using namespace std;
unordered_map<long long int, unordered_map<long long int, long long int> > mp;
long long int path(long long int a, long long int b, long long int x) {
  long long int p1 = a, p2 = b;
  long long int sum = 0;
  while (a != b) {
    if (b > a) {
      b /= 2;
      if (x != -1)
        mp[b][p2] += x;
      else
        sum += mp[b][p2];
      p2 = b;
    } else {
      a /= 2;
      if (x != -1)
        mp[a][p1] += x;
      else
        sum += mp[a][p1];
      p1 = a;
    }
  }
  return sum;
}
int main() {
  int n, i, j, k;
  scanf("%d", &n);
  long long int a, b, x;
  while (n--) {
    scanf("%d", &i);
    if (i == 1) {
      scanf("%I64d%I64d%I64d", &a, &b, &x);
      path(a, b, x);
    } else {
      scanf("%I64d%I64d", &a, &b);
      printf("%I64d\n", path(a, b, -1));
    }
  }
}
