#include <bits/stdc++.h>
using namespace std;
struct pii {
  long long c, v;
  bool operator<(const struct pii &o) const { return c < o.c; }
};
pii mp(long long c, long long v) {
  pii tmp;
  tmp.c = c;
  tmp.v = v;
  return tmp;
}
set<pii> ed;
long long lca(long long x, long long y) {
  set<long long> s;
  while (x > 0) s.insert(x), x /= 2;
  set<long long>::iterator it;
  it = s.find(y);
  while (*it != y || it == s.end()) {
    y /= 2;
    it = s.find(y);
  }
  return y;
}
long long update(long long x, long long y, long long v) {
  long long l = lca(x, y);
  while (x != l) {
    set<pii>::iterator it;
    it = ed.find(mp(x, 0));
    if (it->c == x && it != ed.end()) {
      long long tmp = it->v + v;
      ed.erase(it);
      ed.insert(mp(x, tmp));
    } else
      ed.insert(mp(x, v));
    x /= 2;
  }
  x = y;
  while (x != l) {
    set<pii>::iterator it;
    it = ed.find(mp(x, 0));
    if (it->c == x && it != ed.end()) {
      long long tmp = it->v + v;
      ed.erase(it);
      ed.insert(mp(x, tmp));
    } else
      ed.insert(mp(x, v));
    x /= 2;
  }
}
long long find(long long x, long long y) {
  long long l = lca(x, y);
  long long ret = 0;
  while (x != l) {
    set<pii>::iterator it = ed.find(mp(x, 0));
    if (it->c == x && it != ed.end()) ret += it->v;
    x /= 2;
  }
  x = y;
  while (x != l) {
    set<pii>::iterator it = ed.find(mp(x, 0));
    if (it->c == x && it != ed.end()) ret += it->v;
    x /= 2;
  }
  return ret;
}
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      long long x, y, v;
      scanf("%I64d %I64d %I64d", &x, &y, &v);
      update(x, y, v);
    } else {
      long long x, y;
      scanf("%I64d %I64d", &x, &y);
      printf("%I64d\n", find(x, y));
    }
  }
  return 0;
}
