#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
map<long long, long long> dp;
int q, ty, w;
long long u, v;
int main() {
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%lld%lld", &ty, &u, &v);
    if (ty == 1) {
      scanf("%d", &w);
      while (u != v) {
        if (u > v) swap(u, v);
        dp[v] += w;
        v /= 2;
      }
    } else {
      long long s = 0;
      while (u != v) {
        if (u > v) swap(u, v);
        s += dp[v];
        v /= 2;
      }
      printf("%lld\n", s);
    }
  }
}
