#include <bits/stdc++.h>
using namespace std;
long long qp(long long a, long long b, long long mod) {
  long long t = 1;
  while (b) {
    if (b & 1) t = t * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return t;
}
struct DOT {
  int x;
  int y;
};
inline void read(int &x) {
  int k = 0;
  char f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  x = k * f;
}
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 1e3 + 5;
map<long long, long long> falen;
int main() {
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      long long u, v, w;
      scanf("%lld%lld%lld", &u, &v, &w);
      set<int> vis;
      while (u != 1) {
        vis.insert(u);
        falen[u] += w;
        u >>= 1;
      }
      int opx = 0;
      while (v != 1) {
        if (opx || vis.count(v)) {
          opx = 1;
          falen[v] -= w;
        } else
          falen[v] += w;
        v >>= 1;
      }
    } else {
      long long u, v;
      scanf("%lld%lld", &u, &v);
      long long ans = 0;
      set<int> tmp;
      map<long long, long long> anst;
      long long now = 0;
      long long tu = u;
      while (tu) {
        anst[tu] = now;
        tmp.insert(tu);
        now += falen[tu];
        tu >>= 1;
      }
      long long ansm = 0;
      while (v) {
        if (tmp.count(v)) {
          printf("%lld\n", anst[v] + ansm);
          break;
        }
        ansm += falen[v];
        v >>= 1;
      }
    }
  }
}
