#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <class T>
T power(T a, T b) {
  T result = 1;
  while (b > 0) {
    if (b & 1) result = result * a;
    a = a * a;
    b >>= 1;
  }
  return result;
}
template <class T>
T powerMod(T a, T b, T c) {
  T result = 1 % c;
  while (b > 0) {
    if (b & 1) result = (result * a) % c;
    a = (a * a) % c;
    b >>= 1;
  }
  return result;
}
map<pair<long long, long long>, long long> H;
void findlca(long long a, long long b, long long w) {
  while (1) {
    if (a > b) {
      H[make_pair(a, (a >> 1))] += w;
      a = a >> 1ll;
    } else if (b > a) {
      H[make_pair(b, (b >> 1))] += w;
      b = b >> 1ll;
    } else {
      return;
    }
  }
}
long long findRes(long long a, long long b) {
  long long res = 0;
  while (1) {
    if (a > b) {
      res += H[make_pair(a, (a >> 1))];
      a = a >> 1ll;
    } else if (b > a) {
      res += H[make_pair(b, (b >> 1))];
      b = b >> 1ll;
    } else {
      return res;
    }
  }
}
void eval() {
  long long q, i, type, u, w, v;
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> type >> u >> v;
    if (type == 1) {
      cin >> w;
      findlca(u, v, w);
    } else {
      cout << findRes(u, v) << "\n";
    }
  }
}
int main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  eval();
  return 0;
}
