#include <bits/stdc++.h>
using namespace std;
int q;
long long Ans[1002];
map<long long, long long> cost[2];
void read() { scanf("%d\n", &q); }
void write() {
  while (q--) {
    long long w, u, v;
    int x;
    scanf("%d", &x);
    if (x == 1) {
      scanf("%I64d %I64d %I64d", &v, &u, &w);
      if (v > u) swap(u, v);
      long long ax, ay;
      ax = v;
      ay = u;
      while (ax != ay) {
        if (ax > ay) swap(ax, ay);
        int ry = ay % 2;
        ay /= 2;
        cost[ry][ay] += w;
      }
    } else {
      long long ans = 0;
      scanf("%I64d %I64d", &v, &u);
      long long ax, ay;
      ax = v;
      ay = u;
      while (ax != ay) {
        if (ax > ay) swap(ax, ay);
        int ry = ay % 2;
        ay /= 2;
        ans += cost[ry][ay];
      }
      Ans[++Ans[0]] = ans;
    }
  }
  int i;
  for (i = 1; i <= Ans[0]; ++i) printf("%I64d\n", Ans[i]);
}
int main() {
  read();
  write();
  return 0;
}
