#include <bits/stdc++.h>
using namespace std;
int last_bit_set(long long num) {
  int last_bit = 60;
  while ((num & (1LL << last_bit)) == 0) {
    last_bit--;
  }
  return last_bit;
}
void get_path(long long src, long long goal, vector<long long> &path) {
  while (src > goal) {
    path.push_back(src);
    src /= 2;
  }
  if (path.size() == 0) path.push_back(src);
  if (src == goal) {
    return;
  }
  int last_bit_src = last_bit_set(src);
  int last_bit_goal = last_bit_set(goal);
  long long x = src & (1LL << last_bit_src);
  long long y = goal & (1LL << last_bit_goal);
  while (last_bit_src >= 0 && ((x && y) || (!x && !y))) {
    x = src & (1LL << (--last_bit_src));
    y = goal & (1LL << (--last_bit_goal));
  }
  for (int i = 0; i <= last_bit_src; i++) {
    src /= 2;
    path.push_back(src);
  }
  while (src != goal) {
    if (goal & (1LL << last_bit_goal)) {
      src *= 2;
      src++;
    } else {
      src *= 2;
    }
    last_bit_goal--;
    path.push_back(src);
  }
}
struct Point {
  double x, y;
  Point(double x, double y) {
    this->x = x;
    this->y = y;
  }
};
int main() {
  int n;
  scanf("%d", &n);
  map<pair<long long, long long>, long long> cost;
  for (int q = 0; q < n; q++) {
    int q_type;
    long long v, u;
    scanf("%d %I64d %I64d", &q_type, &u, &v);
    if (q_type == 1) {
      long long w;
      scanf("%I64d", &w);
      vector<long long> path;
      get_path(min(u, v), max(u, v), path);
      for (int i = 0; i < path.size() - 1; i++) {
        cost[{path[i], path[i + 1]}] += w;
        cost[{path[i + 1], path[i]}] += w;
      }
    } else {
      vector<long long> cur_path;
      get_path(min(u, v), max(u, v), cur_path);
      long long ans = 0;
      for (int i = 0; i < cur_path.size() - 1; i++) {
        ans += cost[{cur_path[i], cur_path[i + 1]}];
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
