#include <bits/stdc++.h>
inline void err() { std::cerr << "\033[0m\n"; }
template <class T, class... U>
inline void err(const T &x, const U &...a) {
  std::cerr << x << ' ';
  err(a...);
}
template <class T>
inline void readInt(T &w) {
  char c, p = 0;
  while (!isdigit(c = getchar())) p = c == '-';
  for (w = c & 15; isdigit(c = getchar());) w = w * 10 + (c & 15);
  if (p) w = -w;
}
template <class T, class... U>
inline void readInt(T &w, U &...a) {
  readInt(w), readInt(a...);
}
template <class T, class U>
inline bool smin(T &x, const U &y) {
  return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool smax(T &x, const U &y) {
  return x < y ? x = y, 1 : 0;
}
constexpr int N(2e5 + 5);
int n;
struct Rect {
  int t, b, l, r;
  Rect(int t, int b, int l, int r) : t(t), b(b), l(l), r(r) {}
  inline Rect operator&(const Rect &rhs) const {
    return Rect(std::max(t, rhs.t), std::min(b, rhs.b), std::max(l, rhs.l),
                std::min(r, rhs.r));
  }
  inline long long area() const {
    return 1LL * std::max(0, b - t + 1) * std::max(0, r - l + 1);
  }
};
int pos[N];
std::vector<Rect> rect[N];
std::vector<long long> sum[N];
namespace SegTree {
int min[N << 2];
void update(int o, int l, int r, int x, int y) {
  if (l == r) {
    min[o] = y;
    return;
  }
  int m = l + r >> 1;
  x <= m ? update(o << 1, l, m, x, y) : update(o << 1 | 1, m + 1, r, x, y);
  min[o] = std::min(min[o << 1], min[o << 1 | 1]);
}
int ask(int o, int l, int r, int x) {
  if (x < l) return n;
  if (r <= x) return min[o];
  int m = l + r >> 1;
  return std::min(ask(o << 1, l, m, x), ask(o << 1 | 1, m + 1, r, x));
}
}  // namespace SegTree
bool vis[N];
std::set<int> s;
std::pair<int, int> now[N];
int top[N];
void insert(int i, int v, int l, int r) {
  if (s.count(v)) {
    if (top[v] == i) {
      assert(l == now[v].second + 1);
      now[v].second = r;
      return;
    }
    l = now[v].first;
    rect[v].emplace_back(top[v], i - 1, now[v].first, now[v].second);
    sum[v].push_back(sum[v].back() + rect[v].back().area());
  } else {
    s.insert(v);
  }
  top[v] = i, now[v].first = l, now[v].second = r;
}
int main() {
  readInt(n);
  for (int i = 0; i <= n; i++)
    rect[i].emplace_back(0, -1, 0, -1), sum[i].push_back(0);
  long long ans = 0;
  int mex = 0;
  for (int i = 1; i <= n; i++) {
    int x, l, r, k;
    readInt(x, l, r, k);
    x = (x + ans) % (n + 1);
    l = (l + ans) % i + 1;
    r = (r + ans) % i + 1;
    k = (k + ans) % (n + 1);
    if (l > r) std::swap(l, r);
    ;
    for (vis[x] = 1; vis[mex]; mex++)
      ;
    SegTree::update(1, 1, n, i, x);
    if (pos[x]) SegTree::update(1, 1, n, pos[x], n);
    pos[x] = i;
    auto it = s.find(x);
    if (it != s.end()) {
      s.erase(it);
      auto [p, q] = now[x];
      rect[x].emplace_back(top[x], i - 1, p, q);
      sum[x].push_back(sum[x].back() + rect[x].back().area());
      while (p <= q) {
        int v = SegTree::ask(1, 1, n, q - 1), idx = smin(v, mex) ? 0 : pos[v];
        insert(i, v, idx + 1, q);
        q = idx;
      }
    }
    insert(i, !x, i, i);
    auto &a = rect[k];
    auto &b = sum[k];
    auto qrect = Rect(l, r, l, r);
    ans = 0;
    int p = std::partition_point(
                a.begin(), a.end(),
                [&](const Rect &v) { return v.b < l || v.r < l; }) -
            a.begin();
    int mp = std::partition_point(a.begin(), a.end(),
                                  [&](const Rect &v) { return v.l < l; }) -
             a.begin() - 1;
    int mq = std::partition_point(a.begin(), a.end(),
                                  [&](const Rect &v) { return v.l <= r; }) -
             a.begin() - 1;
    int q = std::partition_point(
                a.begin(), a.end(),
                [&](const Rect &v) { return v.t <= r && v.l <= r; }) -
            a.begin() - 1;
    if (p > q) {
      ans = 0;
    } else if (p == q) {
      ans = (a[p] & qrect).area();
    } else {
      ans = b[q] - b[p - 1];
      ans -= a[p].area() - (a[p] & qrect).area();
      ans -= a[q].area() - (a[q] & qrect).area();
      p++, q--;
      smin(mp, q), smax(mq, mp + 1);
      if (p <= mp)
        assert(a[p].l == a[mp].l),
            ans -= Rect(a[p].t, a[mp].b, a[p].l, l - 1).area();
      if (mq <= q)
        assert(a[mq].l == a[q].l),
            ans -= b[q] - b[mq - 1] - Rect(a[mq].t, a[q].b, a[q].l, r).area();
    }
    if (s.count(k))
      ans += (Rect(top[k], i, now[k].first, now[k].second) & qrect).area();
    printf("%lld\n", ans);
    if (ans == 110) {
      for (auto u : a)
        ;
      ;
    }
  }
  return 0;
}
