#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 1000005;
map<long long, long long> ans;
void upd(long long u, long long val) {
  while (u != 1) {
    ans[u] += val;
    u /= 2;
  }
}
long long get(long long u) {
  long long tot = 0;
  while (u != 1) {
    tot += ans[u];
    u /= 2;
  }
  return tot;
}
long long comm(long long u, long long v) {
  while (1) {
    if (u == v) {
      return u;
    } else if (u > v) {
      u /= 2;
    } else {
      v /= 2;
    }
  }
}
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int qt;
    scanf("%d", &qt);
    vector<int> uv;
    if (qt == 1) {
      long long u, v, cst;
      scanf("%I64d %I64d %I64d", &u, &v, &cst);
      upd(u, cst);
      upd(v, cst);
      upd(comm(u, v), -2 * cst);
    } else {
      long long u, v;
      scanf("%I64d %I64d", &u, &v);
      printf("%I64d\n", get(u) + get(v) - 2 * get(comm(u, v)));
    }
  }
}
