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