#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, tp, f, g, h, p[100], pi, q[100], qi, pas;
map<pair<long long, long long>, long long> m;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a;
  for (b = 1; b <= a; b++) {
    cin >> tp;
    if (tp == 1) {
      cin >> c >> d >> e;
      pi = 0;
      while (c > 0) {
        pi++;
        p[pi] = c % 2;
        c /= 2;
      }
      c = d;
      for (d = 1; d <= pi / 2; d++) {
        swap(p[d], p[pi - d + 1]);
      }
      d = c;
      qi = 0;
      while (d > 0) {
        qi++;
        q[qi] = d % 2;
        d /= 2;
      }
      for (d = 1; d <= qi / 2; d++) {
        swap(q[d], q[qi - d + 1]);
      }
      c = 0;
      f = 0;
      for (d = 1; d <= min(pi, qi); d++) {
        if (p[d] == q[d]) {
          g = c;
          if (p[d] == 0)
            c = c * 2;
          else
            c = c * 2 + 1;
        } else {
          break;
        }
      }
      f = d;
      h = c;
      for (d = f; d <= pi; d++) {
        g = c;
        if (p[d] == 0)
          c = c * 2;
        else
          c = c * 2 + 1;
        m[make_pair(g, c)] += e;
      }
      c = h;
      for (d = f; d <= qi; d++) {
        g = c;
        if (q[d] == 0)
          c = c * 2;
        else
          c = c * 2 + 1;
        m[make_pair(g, c)] += e;
      }
    } else {
      cin >> c >> d;
      pas = 0;
      pi = 0;
      while (c > 0) {
        pi++;
        p[pi] = c % 2;
        c /= 2;
      }
      c = d;
      for (d = 1; d <= pi / 2; d++) {
        swap(p[d], p[pi - d + 1]);
      }
      d = c;
      qi = 0;
      while (d > 0) {
        qi++;
        q[qi] = d % 2;
        d /= 2;
      }
      for (d = 1; d <= qi / 2; d++) {
        swap(q[d], q[qi - d + 1]);
      }
      c = 0;
      f = 0;
      for (d = 1; d <= min(pi, qi); d++) {
        if (p[d] == q[d]) {
          g = c;
          if (p[d] == 0)
            c = c * 2;
          else
            c = c * 2 + 1;
        } else {
          break;
        }
      }
      f = d;
      h = c;
      for (d = f; d <= pi; d++) {
        g = c;
        if (p[d] == 0)
          c = c * 2;
        else
          c = c * 2 + 1;
        pas = pas + m[make_pair(g, c)];
      }
      c = h;
      for (d = f; d <= qi; d++) {
        g = c;
        if (q[d] == 0)
          c = c * 2;
        else
          c = c * 2 + 1;
        pas = pas + m[make_pair(g, c)];
      }
      cout << pas << endl;
    }
  }
  return 0;
}
