#include <bits/stdc++.h>
using namespace std;
struct data {
  long long int u, v;
  int flag;
  friend bool operator<(const struct data a, const struct data b) {
    return a.v > b.v;
  }
};
map<struct data, long long int> book;
void did(long long int u, long long int v, long long int add) {
  while (u != v) {
    if (u > v) {
      long long int fa = u / 2;
      struct data t;
      t.u = fa;
      t.v = u;
      book[t] += add;
      u /= 2;
    } else if (u < v) {
      long long int fa = v / 2;
      struct data t;
      t.u = fa;
      t.v = v;
      v /= 2;
      book[t] += add;
    }
  }
  return;
}
long long int find(long long int u, long long int v) {
  long long int ans = 0;
  while (u != v) {
    if (u > v) {
      long long int fa = u / 2;
      struct data t;
      t.u = fa;
      t.v = u;
      u /= 2;
      ans += book[t];
    } else if (u < v) {
      long long int fa = v / 2;
      struct data t;
      t.u = fa;
      t.v = v;
      v /= 2;
      ans += book[t];
    }
  }
  return ans;
}
void work() {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long int flag, u, v, add;
    scanf("%I64d", &flag);
    if (flag == 1) {
      scanf("%I64d%I64d%I64d", &u, &v, &add);
      did(u, v, add);
    } else {
      scanf("%I64d%I64d", &u, &v);
      printf("%I64d\n", find(u, v));
    }
  }
  return;
}
int main() {
  work();
  return 0;
}
