#include <bits/stdc++.h>
using namespace std;
typedef long double ldb;
const int maxn = 1 << 21;
const int N = int(1e5);
const long long mod = int(1e9) + 7;
const long long inf = 1e18;
const double PI = 3.1415926536;
inline int Set(int n, int pos) { return n = n | 1 << pos; }
inline bool check(int n, int pos) { return n & 1 << pos; }
inline int Reset(int n, int pos) { return n = n & ~(1 << pos); }
inline int lastbit(int n) { return n & (-n); }
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return (a * b) / gcd(a, b); }
inline long long power(long long a, long long b) {
  long long ans = 1;
  a = a % mod;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
inline long long invmod(long long a) {
  long long ans = power(a, mod - 2);
  return ans;
}
inline long long Egcd(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = Egcd(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
inline int bs(int arr[], int l, int r, int item) {
  if (l == r) {
    if (arr[l] == item)
      return r;
    else
      return -1;
  }
  if (item <= arr[(l + r) / 2])
    return bs(arr, l, (l + r) / 2, item);
  else
    return bs(arr, (l + r) / 2 + 1, r, item);
}
inline void fastin(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return;
}
int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nleap[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
map<pair<long long, long long>, long long> m;
map<long long, bool> visited;
void update(long long v, long long u, long long w) {
  bool flag = true;
  while (v != 1) {
    m[make_pair(v, v / 2)] += w;
    m[make_pair(v / 2, v)] += w;
    visited[v] = true;
    v /= 2;
    if (v == u) {
      flag = false;
      break;
    }
  }
  if (flag) {
    while (u != 1) {
      m[make_pair(u, u / 2)] += w;
      m[make_pair(u / 2, u)] += w;
      u /= 2;
      if (visited[u]) break;
    }
    while (u != 1) {
      m[make_pair(u, u / 2)] -= w;
      m[make_pair(u / 2, u)] -= w;
      u /= 2;
    }
  }
}
void query(long long v, long long u) {
  long long ans = 0;
  bool flag = true;
  while (v != 1) {
    ans += m[make_pair(v, v / 2)];
    visited[v] = true;
    v /= 2;
    if (v == u) {
      flag = false;
      break;
    }
  }
  if (flag) {
    while (u != 1) {
      ans += m[make_pair(u, u / 2)];
      u /= 2;
      if (visited[u]) break;
    }
    while (u != 1) {
      ans -= m[make_pair(u, u / 2)];
      u /= 2;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    long long v, u, w;
    int event;
    cin >> event;
    visited.clear();
    if (event == 1) {
      cin >> v >> u >> w;
      update(max(u, v), min(u, v), w);
    } else {
      cin >> v >> u;
      query(max(u, v), min(u, v));
    }
  }
  return 0;
}
