#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
map<long long, long long> M;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long oper, u, v, w;
    scanf("%lld", &oper);
    if (oper == 1) {
      scanf("%lld%lld%lld", &u, &v, &w);
      while (u != v) {
        if (u > v) {
          M[u] += w;
          u /= 2;
        } else {
          M[v] += w;
          v /= 2;
        }
      }
    } else {
      scanf("%lld%lld", &u, &v);
      long long ans = 0;
      while (u != v) {
        if (u > v) {
          ans += M[u];
          u /= 2;
        } else {
          ans += M[v];
          v /= 2;
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
