#include <bits/stdc++.h>
using namespace std;
long long int u, v, w;
long long int cost[2000];
long long int findit(long long int i, long long int j) {
  if (i > j) swap(i, j);
  long long int a = i;
  long long int b = j;
  long long int aa = 0, bb = 0;
  while (j >= 1) {
    j = j / 2;
    aa++;
  }
  while (i >= 1) {
    i = i / 2;
    bb++;
  }
  if (aa > bb) {
    while (aa > bb) {
      b = b / 2;
      aa--;
    }
  } else {
    while (bb > aa) {
      a = a / 2;
      bb--;
    }
  }
  while (a != b) {
    a = a / 2;
    b = b / 2;
  }
  return a;
}
map<pair<long long int, long long int>, long long int> graph;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int num;
    scanf("%d", &num);
    if (num == 1) {
      cin >> u >> v >> w;
      long long int ans = findit(u, v);
      while (u != ans) {
        graph[make_pair(u, u / 2)] += w;
        graph[make_pair(u / 2, u)] += w;
        u = u / 2;
      }
      while (v != ans) {
        graph[make_pair(v, v / 2)] += w;
        graph[make_pair(v / 2, v)] += w;
        v = v / 2;
      }
    } else {
      int i;
      cin >> u >> v;
      long long int ans = findit(u, v);
      long long int madher = 0;
      while (u != ans) {
        madher += graph[make_pair(u, u / 2)];
        u = u / 2;
      }
      while (v != ans) {
        madher += graph[make_pair(v, v / 2)];
        v = v / 2;
      }
      cout << madher << endl;
    }
  }
  return 0;
}
