#include <bits/stdc++.h>
using namespace std;
pair<pair<long long, long long>, pair<long long, int> > a[1010];
long long lcs(long long u, long long v) {
  while (u != v) {
    if (u < v) {
      swap(u, v);
    }
    u /= 2;
  }
  return u;
}
long long len(long long u1, long long v1, long long u2, long long v2) {
  long long ans = 0;
  long long v = lcs(u1, u2);
  if (lcs(v1, v2) != min(v1, v2)) {
    return 0;
  }
  while (v >= max(v1, v2)) {
    ++ans;
    v /= 2;
  }
  return max(0ll, ans - 1);
}
int main() {
  int q;
  cin >> q;
  int cnt = 0;
  for (int i = 1; i <= q; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      if (u > v) {
        swap(u, v);
      }
      a[cnt] = make_pair(make_pair(u, v), make_pair(lcs(u, v), w));
      ++cnt;
      continue;
    }
    long long u, v;
    cin >> u >> v;
    if (u > v) {
      swap(u, v);
    }
    long long ans = 0;
    long long z = lcs(u, v);
    for (int j = 0; j < cnt; ++j) {
      ans += a[j].second.second *
             (len(u, z, a[j].first.first, a[j].second.first) +
              len(v, z, a[j].first.first, a[j].second.first) +
              len(u, z, a[j].first.second, a[j].second.first) +
              len(v, z, a[j].first.second, a[j].second.first));
    }
    cout << ans << endl;
  }
  return 0;
}
