#include <bits/stdc++.h>
const long long lim = 1e5 + 5;
using namespace std;
vector<long long> v;
bool vis[lim], vis1[lim];
long long n, m, k;
set<long long> s;
long long ans, cnt, sum = 0;
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
map<long long, long long> mp;
long long lca(long long v, long long u, long long w) {
  long long ans = 0;
  while (v != u) {
    if (v < u) swap(v, u);
    if (mp[v]) ans += mp[v];
    if (w != 0) mp[v] += w;
    v >>= 1;
  }
  return ans;
}
signed main() {
  long long t = 1, a, b, c, d;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    if (a == 1) {
      cin >> d;
      lca(b, c, d);
    } else
      cout << lca(b, c, 0) << "\n";
  }
}
