#include <bits/stdc++.h>
using namespace std;
void swap(long long &a, long long &b) {
  auto tm = a;
  a = b;
  b = tm;
}
const long long mod = 1000000007;
const long long mod2 = 998244353;
const long long INF = (1LL << 50) - 1;
const long long N = 2e5 + 5;
map<pair<long long, long long>, long long> m;
void update(long long x, long long y, long long w) {
  while (x != y) {
    if (y > x) swap(x, y);
    long long tm = x / 2;
    m[{x, tm}] += w;
    m[{tm, x}] += w;
    x = tm;
  }
}
long long query(long long x, long long y) {
  long long ct = 0;
  while (x != y) {
    if (y > x) swap(x, y);
    long long tm = x / 2;
    ct += m[{x, tm}];
    x = tm;
  }
  return ct;
}
void bheja_fry() {
  long long q;
  cin >> q;
  while (q--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long x, y, w;
      cin >> x >> y >> w;
      update(x, y, w);
    } else {
      long long x, y;
      cin >> x >> y;
      cout << query(x, y) << "\n";
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long(i) = (1); (i) < (t + 1); (i)++) {
    bheja_fry();
    if (i < t) cout << "\n";
  }
  return 0;
}
