#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int q;
  cin >> q;
  map<pair<long long, long long>, long long> m;
  for (int i = 0; i < q; i++) {
    map<pair<long long, long long>, long long> czy;
    long long a;
    cin >> a;
    if (a == 1) {
      long long b, c, d;
      cin >> b >> c >> d;
      while (b != 1) {
        m[make_pair(b / 2, b)] += d;
        czy[make_pair(b / 2, b)] = 1;
        b /= 2;
      }
      while (c != 1) {
        if (czy[make_pair(c / 2, c)] == 1) {
          m[make_pair(c / 2, c)] -= d;
        } else
          m[make_pair(c / 2, c)] += d;
        c /= 2;
      }
    } else {
      long long b, c;
      cin >> b >> c;
      long long odp = 0;
      while (b != 1) {
        odp += m[make_pair(b / 2, b)];
        czy[make_pair(b / 2, b)] = 1;
        b /= 2;
      }
      while (c != 1) {
        if (czy[make_pair(c / 2, c)] == 1) {
          odp -= m[make_pair(c / 2, c)];
        } else
          odp += m[make_pair(c / 2, c)];
        c /= 2;
      }
      cout << odp << endl;
    }
  }
}
