#include <bits/stdc++.h>
using namespace std;
unsigned long long get_upper_bound(unsigned long long a) {
  int k = 0;
  while (a > 1) {
    a /= 2;
    k++;
  }
  unsigned long long x = 1;
  x <<= k + 1;
  return x;
}
void update_road_cost(
    unsigned long long a, unsigned long long c,
    unordered_map<unsigned long long, unsigned long long>& map) {
  if (map.find(a) == map.end()) {
    map.emplace(a, c);
  } else {
    map[a] = map[a] + c;
  }
}
unsigned long long get_road_cost(
    unsigned long long a,
    unordered_map<unsigned long long, unsigned long long>& map) {
  if (map.find(a) == map.end()) {
    return 0;
  } else {
    return map[a];
  }
}
void new_rule(unsigned long long u, unsigned long long v, unsigned long long w,
              unordered_map<unsigned long long, unsigned long long>& map) {
  if (u < v) {
    unsigned long long tmp = u;
    u = v;
    v = tmp;
  }
  unsigned long long x = get_upper_bound(v);
  while (u >= x) {
    update_road_cost(u, w, map);
    u /= 2;
  }
  while (u != v) {
    update_road_cost(u, w, map);
    update_road_cost(v, w, map);
    u /= 2;
    v /= 2;
  }
}
unsigned long long cuddle(
    unsigned long long u, unsigned long long v,
    unordered_map<unsigned long long, unsigned long long>& map) {
  unsigned long long sum = 0;
  if (u < v) {
    unsigned long long tmp = u;
    u = v;
    v = tmp;
  }
  unsigned long long x = get_upper_bound(v);
  while (u >= x) {
    sum += get_road_cost(u, map);
    u /= 2;
  }
  while (u != v) {
    sum += get_road_cost(u, map);
    sum += get_road_cost(v, map);
    u /= 2;
    v /= 2;
  }
  return sum;
}
int main(int argc, char** argv) {
  unordered_map<unsigned long long, unsigned long long> map;
  int q;
  int t;
  unsigned long long u, v, w;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t >> u >> v;
    if (t == 1) {
      cin >> w;
      new_rule(u, v, w, map);
    } else {
      cout << cuddle(u, v, map) << '\n';
    }
  }
  return 0;
}
