#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 1000006;
const int MAX2 = 207;
const int BASE = 1000000000;
const int CNT = 500;
const int MOD = 1000000007;
map<long long, long long> m;
long long lca(long long a, long long b) {
  if (a > b) swap(a, b);
  while (b % a) b >>= 1;
  return b;
}
void add(long long a, long long b, int val) {
  while (a != b) {
    if (a < b) swap(a, b);
    m[a] += val;
    a >>= 1;
  }
}
long long get(long long a, long long b) {
  long long res = 0;
  while (a != b) {
    if (a < b) swap(a, b);
    if (m.count(a)) res += m[a];
    a >>= 1;
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    long long a, b, t;
    cin >> t >> a >> b;
    if (t == 1) {
      long long w;
      cin >> w;
      add(a, b, w);
    } else {
      cout << get(a, b) << endl;
    }
  }
  return 0;
}
