#include <bits/stdc++.h>
using namespace std;
const int Max1 = 1e5 + 4;
const int Max2 = 2e5 + 4;
const int Mod = 1e9 + 7;
long long int level(long long int n) {
  long long int level = 0;
  if (n && !(n & (n - 1))) {
    long long int pp = n;
    while (pp) {
      pp /= 2;
      level++;
    }
    return level;
  } else {
    n--;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n |= n >> 32;
    long long int pp = ++n;
    while (pp) {
      pp /= 2;
      level++;
    }
    return --level;
  }
}
set<pair<long long int, long long int> > edge_list(long long int u,
                                                   long long int v) {
  set<pair<long long int, long long int> > edges;
  long long int levelu = level(u);
  long long int levelv = level(v);
  long long int temp, other;
  if (levelu > levelv) {
    temp = u;
    other = v;
  } else {
    temp = v;
    other = u;
  }
  while (temp > 1) {
    edges.insert({temp / 2, temp});
    temp /= 2;
  }
  while (other > 1) {
    pair<long long int, long long int> edge = {other / 2, other};
    if (!(edges.find(edge) != edges.end())) {
      edges.insert(edge);
    } else {
      edges.erase(edge);
    }
    other /= 2;
  }
  return edges;
}
void solve() {
  long long int q;
  cin >> q;
  map<pair<long long int, long long int>, long long int> cost;
  while (q--) {
    long long int p, u, v;
    cin >> p;
    if (p == 1) {
      long long int w;
      cin >> u >> v >> w;
      set<pair<long long int, long long int> > edges = edge_list(u, v);
      for (pair<long long int, long long int> edge : edges) cost[edge] += w;
    } else if (p == 2) {
      cin >> u >> v;
      long long int ans = 0;
      set<pair<long long int, long long int> > edges = edge_list(u, v);
      for (pair<long long int, long long int> edge : edges) ans += cost[edge];
      cout << ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
