#include <bits/stdc++.h>
using namespace std;
long long q, l, a, b, c, i, t, pu[1000], n, cost[1000][200], s, sum, bl, br;
void ff(long long a, long long b, long long t) {
  n = 2;
  while (true) {
    if (a < b) {
      cost[t][n] = b;
      b /= 2;
      n++;
    } else {
      cost[t][n] = a;
      a /= 2;
      n++;
    }
    if (a == b) {
      cost[t][n] = a;
      n++;
      break;
    }
  }
  cost[t][1] = n;
}
void f(long long a, long long b) {
  n = 1;
  while (true) {
    if (a < b) {
      pu[n] = b;
      b /= 2;
      n++;
    } else {
      pu[n] = a;
      a /= 2;
      n++;
    }
    if (a == b) {
      pu[n] = a;
      n++;
      break;
    }
  }
  pu[0] = n;
}
int main() {
  cin >> q;
  for (int z = 0; z < q; z++) {
    cin >> l;
    if (l == 1) {
      cin >> a >> b >> cost[t][0];
      ff(a, b, t);
      t++;
    } else {
      sum = 0;
      cin >> a >> b;
      f(a, b);
      for (int i = 0; i < t; i++) {
        s = 0;
        for (int k = 2; k < cost[i][1]; k++) {
          bl = 1;
          br = pu[0] - 1;
          while (true) {
            if (pu[br] == cost[i][k]) {
              s++;
              break;
            }
            if (br - bl == 1) {
              if (pu[bl] == cost[i][k]) {
                s++;
                break;
              } else
                break;
            }
            if (pu[(bl + br) / 2] >= cost[i][k])
              bl = (bl + br) / 2;
            else
              br = (bl + br) / 2;
          }
        }
        if (s == 0) continue;
        sum += (s - 1) * cost[i][0];
      }
      cout << sum << endl;
    }
  }
  return 0;
}
