#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> dp;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int x;
    long long u, v;
    scanf("%d", &x);
    scanf("%I64d%I64d", &v, &u);
    if (x == 1) {
      int val;
      scanf("%d", &val);
      while (v != u) {
        if (v > u) {
          dp[make_pair(v, v / 2)] += val;
          v = v >> 1;
        } else {
          dp[make_pair(u, u / 2)] += val;
          u = u >> 1;
        }
      }
    } else {
      long long sol = 0;
      while (v != u) {
        if (v > u) {
          sol += dp[make_pair(v, v >> 1)];
          v = v >> 1;
        } else {
          sol += dp[make_pair(u, u >> 1)];
          u = u >> 1;
        }
      }
      printf("%I64d\n", sol);
    }
  }
  return 0;
}
