#include <bits/stdc++.h>
using namespace std;
int q, i, op;
long long u, v, w, ans;
map<long long, long long> sc;
int main() {
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%I64d%I64d%I64d", &u, &v, &w);
      while (u != v) {
        if (u > v) {
          sc[u] += w;
          u /= 2;
        }
        if (u < v) {
          sc[v] += w;
          v /= 2;
        }
      }
    } else {
      scanf("%I64d%I64d", &u, &v);
      ans = 0;
      while (u != v) {
        if (u > v) {
          ans += sc[u];
          u /= 2;
        }
        if (u < v) {
          ans += sc[v];
          v /= 2;
        }
      }
      printf("%I64d\n", ans);
    }
  }
}
