#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const long long M = 1e9 + 7;
map<pair<long long, long long>, long long> W;
void fun1(long long u, long long v, long long w) {
  pair<long long, long long> p;
  while (u != v) {
    if (u < v) swap(u, v);
    p.first = u;
    p.second = u >> 1;
    u >>= 1;
    if (!W.count(p))
      W[p] = w;
    else
      W[p] += w;
  }
}
void fun2(long long u, long long v) {
  long long sum = 0;
  pair<long long, long long> p;
  while (u != v) {
    if (u < v) swap(u, v);
    p.first = u;
    p.second = u >> 1;
    u >>= 1;
    if (W.count(p)) sum += W[p];
  }
  printf("%lld\n", sum);
}
int main(void) {
  int q, op;
  long long u, v, w;
  while (~scanf("%d", &q)) {
    while (q--) {
      scanf("%d%lld%lld", &op, &u, &v);
      if (op == 1) {
        scanf("%lld", &w);
        fun1(u, v, w);
      } else {
        fun2(u, v);
      }
    }
  }
  return 0;
}
