#include <bits/stdc++.h>
using namespace std;
long long maxarr(vector<long long> &arr);
long long minarr(vector<long long> &arr);
long long gcd(long long a, long long b);
long long choose(long long n, long long k);
bool isprime(long long n);
void setprime(bool isprime[], long long n);
int main() {
  long long n;
  scanf("%lld", &n);
  map<long long, long long> hm;
  long long code, u, v, w;
  while (n-- != 0) {
    scanf("%lld", &code);
    if (code == 1) {
      scanf("%lld %lld %lld", &u, &v, &w);
      while (u != v) {
        if (u > v) {
          hm[u] += w;
          u = u / 2;
        } else {
          hm[v] += w;
          v = v / 2;
        }
      }
    } else {
      long long count = 0;
      scanf("%lld %lld", &u, &v);
      while (v != u) {
        if (u > v) {
          count += hm[u];
          u = u / 2;
        } else {
          count += hm[v];
          v = v / 2;
        }
      }
      cout << count << endl;
    }
  }
  return 0;
}
long long maxarr(vector<long long> &arr) {
  long long maxll = LONG_LONG_MIN;
  for (long long i = 0; i < arr.size(); i++) maxll = max(arr[i], maxll);
  return maxll;
}
long long minarr(vector<long long> &arr) {
  long long minll = LONG_LONG_MAX;
  for (long long i = 0; i < arr.size(); i++) minll = min(arr[i], minll);
  return minll;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void setprime(bool isprime[], long long n) {
  for (long long i = 0; i < n; i++) isprime[i] = true;
  isprime[0] = false;
  isprime[1] = false;
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; i * j < n; j++) isprime[i * j] = false;
  }
}
