#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int siz = 2e5 + 5;
int n, m, a[siz];
map<long long, long long> mp;
long long go(long long u, long long v, long long w) {
  long long ans = 0;
  while (u != v) {
    if (u > v) swap(u, v);
    if (mp.find(v) != mp.end()) ans += mp[v];
    if (w != -1) mp[v] += w;
    v /= 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long typ, u, v;
    cin >> typ >> u >> v;
    if (typ == 1) {
      long long w;
      cin >> w;
      go(u, v, w);
    } else
      cout << go(u, v, -1) << endl;
  }
}
