#include <bits/stdc++.h>
using namespace std;
long long tavan(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) res *= (n & 1) ? a : 1, res %= mod, n /= 2, a *= a, a %= mod;
  return res;
}
const long long N = ((long long)301 * 1000);
const long long INF = ((long long)2e18);
const long long MOD = ((long long)109 + 7);
long long q;
map<long long, long long> c;
long long lca(long long x, long long y) {
  deque<long long> x1, y1;
  while (x) {
    x1.push_front(x % 2);
    x /= 2;
  }
  while (y) {
    y1.push_front(y % 2);
    y /= 2;
  }
  long long i = 0, num = 0;
  for (; i < min((long long)x1.size(), (long long)y1.size()); i++) {
    if (x1[i] != y1[i]) return num;
    num *= 2;
    num += x1[i];
  }
  return num;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    long long t, x, y, w;
    cin >> t >> x >> y;
    if (t == 1) {
      cin >> w;
      long long p = lca(x, y);
      while (x != p) {
        c[x] += w;
        x /= 2;
      }
      while (y != p) {
        c[y] += w;
        y /= 2;
      }
    }
    if (t == 2) {
      long long p = lca(x, y), ans = 0;
      while (x != p) {
        ans += c[x];
        x /= 2;
      }
      while (y != p) {
        ans += c[y];
        y /= 2;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
