#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 5111;
const int INF = 1 << 30;
const ll LNF = 1LL << 60;
int n, q;
ll a, b, w;
map<ll, ll> m;
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &q);
    if (q == 1) {
      scanf("%I64d%I64d%I64d", &a, &b, &w);
      if (a > b) swap(a, b);
      while (a != b) {
        if (a > b) {
          m[a] += w;
          a /= 2;
        } else {
          m[b] += w;
          b /= 2;
        }
      }
    } else {
      scanf("%I64d%I64d", &a, &b);
      if (a > b) swap(a, b);
      ll res = 0LL;
      while (a != b) {
        if (a > b) {
          res += m[a];
          a /= 2;
        } else {
          res += m[b];
          b /= 2;
        }
      }
      printf("%I64d\n", res);
    }
  }
  return 0;
}
