#include <bits/stdc++.h>
using namespace std;
map<long long, long long> je;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int choice;
    long long u, v, w;
    scanf("%d%lld%lld", &choice, &u, &v);
    if (choice == 1) {
      scanf("%lld", &w);
      if (u > v) swap(u, v);
      while (u != v) {
        while (u > v) {
          je[u] += w;
          u >>= 1;
        }
        while (v > u) {
          je[v] += w;
          v >>= 1;
        }
      }
    } else {
      long long ans = 0;
      if (u > v) swap(u, v);
      while (u != v) {
        while (u > v) {
          ans += je[u];
          u >>= 1;
        }
        while (v > u) {
          ans += je[v];
          v >>= 1;
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
