#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int N = 100100;
map<long long, long long> road;
map<long long, bool> used;
vector<long long> arr, arr2;
void inc(long long u, long long v, long long w) {
  if (u > v) swap(u, v);
  arr.clear();
  arr2.clear();
  while (v > 1) {
    arr.push_back(v);
    v /= 2;
  }
  while (u > 1) {
    arr2.push_back(u);
    u /= 2;
  }
  long long pivot = -1;
  used.clear();
  for (int i = 0; i < arr.size(); i++) used[arr[i]] = true;
  for (int i = 0; i < arr2.size(); i++)
    if (used[arr2[i]]) {
      pivot = arr2[i];
      break;
    }
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] == pivot) break;
    road[arr[i]] += w;
  }
  for (int i = 0; i < arr2.size(); i++) {
    if (arr2[i] == pivot) break;
    road[arr2[i]] += w;
  }
}
long long anw(long long u, long long v) {
  if (u > v) swap(u, v);
  long long res = 0;
  arr.clear();
  arr2.clear();
  while (v > 1) {
    arr.push_back(v);
    v /= 2;
  }
  while (u > 1) {
    arr2.push_back(u);
    u /= 2;
  }
  long long pivot = -1;
  used.clear();
  for (int i = 0; i < arr.size(); i++) used[arr[i]] = true;
  for (int i = 0; i < arr2.size(); i++)
    if (used[arr2[i]]) {
      pivot = arr2[i];
      break;
    }
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] == pivot) break;
    res += road[arr[i]];
  }
  for (int i = 0; i < arr2.size(); i++) {
    if (arr2[i] == pivot) break;
    res += road[arr2[i]];
  }
  return res;
}
int q;
int main() {
  cin >> q;
  while (q--) {
    long long type, u, v, w;
    cin >> type >> u >> v;
    if (type == 1) {
      cin >> w;
      inc(u, v, w);
    } else {
      cout << anw(u, v) << endl;
    }
  }
}
