#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 2e18;
const ll mod = 998244353;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
map<pair<ll, ll>, ll> par, cost;
int main() {
  int n, tp;
  ll x, y, w;
  cin >> n;
  while (n--) {
    cin >> tp;
    if (tp == 1) {
      cin >> x >> y >> w;
      while (x != y) {
        if (x > y) {
          cost[{x, x / 2}] += w;
          cost[{x / 2, x}] += w;
          x /= 2;
        } else {
          cost[{y, y / 2}] += w;
          cost[{y / 2, y}] += w;
          y /= 2;
        }
      }
    } else {
      cin >> x >> y;
      ll ans = 0;
      while (x != y) {
        if (x > y) {
          ans += cost[{x, x / 2}];
          x /= 2;
        } else {
          ans += cost[{y, y / 2}];
          y /= 2;
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
