#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, i, t, sum, temp, a, b, w, k;
  map<long long int, long long int> cost;
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> t;
    sum = 0;
    map<long long int, int> map1;
    if (t == 1) {
      cin >> a >> b >> w;
      if (b > a) {
        temp = b;
        b = a;
        a = temp;
      }
      k = a;
      while (k != b) {
        k = k / 2;
        map1[k] = 1;
        if (k == 1) break;
      }
      if (k == b) {
        k = a;
        while (k > b) {
          cost[k] = cost[k] + w;
          k = k / 2;
        }
      } else {
        k = b;
        while (map1[k] != 1) {
          cost[k] = cost[k] + w;
          k = k / 2;
        }
        while (a != k) {
          cost[a] = cost[a] + w;
          a = a / 2;
        }
      }
    } else {
      cin >> a >> b;
      if (b > a) {
        temp = b;
        b = a;
        a = temp;
      }
      k = a;
      while (k != b) {
        k = k / 2;
        map1[k] = 1;
        if (k == 1) break;
      }
      if (k == b) {
        k = a;
        while (k > b) {
          sum = sum + cost[k];
          k = k / 2;
        }
      } else {
        k = b;
        while (map1[k] != 1) {
          sum = sum + cost[k];
          k = k / 2;
        }
        while (a != k) {
          sum = sum + cost[a];
          a = a / 2;
        }
      }
      cout << sum << endl;
    }
  }
}
