#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> g;
void build(long long v, long long u, int w) {
  while (u != v) {
    if (u < v) {
      g[{v, v / 2}] += w;
      v /= 2;
    } else {
      g[{u, u / 2}] += w;
      u /= 2;
    }
  }
}
long long sol(long long v, long long u) {
  long long ans = 0;
  while (u != v) {
    if (u < v) {
      ans += g[{v, v / 2}];
      v /= 2;
    } else {
      ans += g[{u, u / 2}];
      u /= 2;
    }
  }
  return ans;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int t;
    long long u, v;
    cin >> t;
    if (t == 1) {
      int w;
      cin >> v >> u >> w;
      build(v, u, w);
    } else {
      cin >> v >> u;
      cout << sol(v, u) << endl;
    }
  }
}
