#include <bits/stdc++.h>
using namespace std;
map<long long, bool> mp, mp1;
map<long long, bool>::iterator it, titr;
map<pair<long long, long long>, long long> cost;
void convert(long long u, long long v, long long w) {
  while (u > 0) {
    mp1[u] = true;
    mp[u] = true;
    u /= 2;
  }
  long long par = -1;
  while (!mp[v]) {
    par = v;
    v /= 2;
    cost[{v, par}] += w;
  }
  it = mp1.lower_bound(v);
  titr = ++it;
  it--;
  while (titr != mp1.end()) {
    cost[{it->first, titr->first}] += w;
    it = titr++;
  }
}
long long findmin(long long u, long long v) {
  long long val = 0;
  while (u > 0) {
    mp1[u] = true;
    mp[u] = true;
    u /= 2;
  }
  long long par;
  while (!mp[v]) {
    par = v;
    v /= 2;
    val += cost[{v, par}];
  }
  it = mp1.lower_bound(v);
  titr = it++;
  while (titr != mp1.end()) {
    val += cost[{it->first, titr->first}];
    it = titr++;
  }
  return val;
}
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long x, u, v, w;
    cin >> x;
    if (x == 1) {
      cin >> u >> v >> w;
      mp.clear();
      mp1.clear();
      convert(u, v, w);
    } else {
      cin >> u >> v;
      mp.clear();
      mp1.clear();
      cout << findmin(u, v) << "\n";
    }
  }
}
