#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mm = 10005;
const int MOD = 1000000;
const int INF = 1e9 + 2;
map<long long, long long> M;
long long get_lca(long long a, long long b) {
  long long i, j = 0, ans, temp;
  if (a < b) swap(a, b);
  i = a;
  while (i) {
    i = i >> 1;
    j++;
  }
  j--;
  while (1) {
    if ((a >> j & 1) == (b >> j) & 1) break;
    a = a >> 1;
    j--;
  }
  if (a == b) return a;
  while (1) {
    if ((a / 2) == (b / 2)) return a / 2;
    a = a / 2;
    b = b / 2;
  }
}
int main() {
  int n, op;
  long long u, v, w;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%I64d%I64d%I64d", &u, &v, &w);
      long long lca = get_lca(u, v);
      while (u != lca) {
        M[u] += w;
        u /= 2;
      }
      while (v != lca) {
        M[v] += w;
        v /= 2;
      }
    } else {
      scanf("%I64d%I64d", &u, &v);
      long long ans = 0;
      long long lca = get_lca(u, v);
      while (u != lca) {
        ans += M[u];
        u /= 2;
      }
      while (v != lca) {
        ans += M[v];
        v /= 2;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
