#include <bits/stdc++.h>
using namespace std;
double eps = 0.0000001;
double pi = acos(-1);
long long fastpower(long long b, long long p) {
  long long ans = 1;
  while (p) {
    if (p % 2) {
      ans = (ans * b);
    }
    b = b * b;
    p /= 2;
  }
  return ans;
}
long long fastpowermod(long long b, long long p, long long m) {
  long long ans = 1;
  while (p) {
    if (p % 2) {
      ans = ((ans % m) * (b % m)) % m;
    }
    b = ((b % m) * (b % m)) % m;
    p /= 2;
  }
  return ans % m;
}
string makeitstring(long long n) {
  string ans;
  bool ch = 0;
  if (n < 0) {
    n *= -1;
    ch = 1;
  }
  if (n == 0) {
    ans = "0";
  };
  while (n) {
    long long mo = n % 10;
    mo += 48;
    char m = mo;
    ans = m + ans;
    n /= 10;
  }
  if (ch) {
    ans = '-' + ans;
  }
  return ans;
}
bool compare(double f, double s) { return (abs(f - s) < eps); }
long long gcd(long long a, long long b) {
  while (b != 0) {
    long long a2 = a;
    a = b;
    b = a2 % b;
  }
  return a;
}
const int N = 2e6 + 1;
const int M = 1e9 + 7;
unordered_map<long long, long long> m;
void add(long long u, long long v, long long val) {
  if (u == v) {
    return;
  }
  if (u < v) {
    swap(u, v);
  }
  m[u] += val;
  add(u / 2, v, val);
  return;
}
long long solve(long long u, long long v) {
  if (u == v) {
    return 0;
  }
  if (u < v) {
    swap(u, v);
  }
  return m[u] + solve(u / 2, v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int q;
  cin >> q;
  vector<long long> v;
  for (int i = 0; i < q; i++) {
    long long x, u, v, w;
    cin >> x >> u >> v;
    if (x == 1) {
      cin >> w;
      add(u, v, w);
    } else {
      cout << solve(u, v) << endl;
    }
  }
  return 0;
}
