#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &a) {
  static char c;
  static int fh;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    fh = -1, a = 0;
  else
    fh = 1, a = c - '0';
  while ((c = getchar()) <= '9' && c >= '0') a = (a << 3) + (a << 1) + c - '0';
  a = a * fh;
}
template <class T>
void write(T a) {
  if (a == 0)
    putchar('0');
  else {
    if (a < 0) putchar('-'), a = -a;
    static char c[30];
    static int c0;
    c0 = 0;
    while (a) c[++c0] = a % 10 + '0', a /= 10;
    while (c0) putchar(c[c0--]);
  }
}
map<long long int, long long int> m;
int main() {
  int queries;
  read(queries);
  long long int ans, u, v, w, k;
  while (queries--) {
    read(k);
    ans = 0;
    if (k == 1) {
      read(u);
      read(v);
      read(w);
    } else {
      read(u);
      read(v);
    }
    while (u != v) {
      if (u < v) swap(u, v);
      k == 1 ? m[u] += w : ans += m[u];
      u = u / 2;
    }
    if (k == 2) {
      write(ans);
      putchar('\n');
    }
  }
  return 0;
}
