#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--]);
  }
}
struct Edge {
  long long int u, v, w;
};
Edge q[1005];
int main() {
  int queries;
  read(queries);
  long long int k, u, v, w, idx = 0, i, ans;
  long long int n1, n2;
  while (queries--) {
    read(k);
    if (k == 1) {
      read(q[idx].u);
      read(q[idx].v);
      read(q[idx].w);
      idx++;
    } else {
      read(u);
      read(v);
      n1 = (long long int)log2l(u), n2 = (long long int)log2l(v);
      map<pair<long long int, long long int>, bool> m;
      if (n1 > n2) {
        while (n1 > n2) {
          m.insert(pair<pair<long long int, long long int>, long long int>(
              pair<long long int, long long int>(u / 2, u), 1));
          u = u / 2;
          n1--;
        }
      } else if (n2 > n1) {
        while (n2 > n1) {
          m.insert(pair<pair<long long int, long long int>, long long int>(
              pair<long long int, long long int>(v / 2, v), 1));
          v = v / 2;
          n2--;
        }
      }
      while (u != v) {
        m.insert(pair<pair<long long int, long long int>, long long int>(
            pair<long long int, long long int>(u / 2, u), 1));
        u = u / 2;
        m.insert(pair<pair<long long int, long long int>, long long int>(
            pair<long long int, long long int>(v / 2, v), 1));
        v = v / 2;
      }
      ans = 0;
      for (i = 0; i < idx; i++) {
        u = q[i].u, v = q[i].v, w = q[i].w;
        n1 = (long long int)log2l(u), n2 = (long long int)log2l(v);
        if (n1 > n2) {
          while (n1 > n2) {
            if (m.find(pair<long long int, long long int>(u / 2, u)) != m.end())
              ans += w;
            u = u / 2;
            n1--;
          }
        } else if (n2 > n1) {
          while (n2 > n1) {
            if (m.find(pair<long long int, long long int>(v / 2, v)) != m.end())
              ans += w;
            v = v / 2;
            n2--;
          }
        }
        while (u != v) {
          if (m.find(pair<long long int, long long int>(u / 2, u)) != m.end())
            ans += w;
          u = u / 2;
          if (m.find(pair<long long int, long long int>(v / 2, v)) != m.end())
            ans += w;
          v = v / 2;
        }
      }
      write(ans);
      putchar('\n');
    }
  }
  return 0;
}
