#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
template <class t>
void chmax(t& first, t second) {
  if (first < second) first = second;
}
template <class t>
void chmin(t& first, t second) {
  if (first > second) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
template <ll i, class T>
void print_tuple(ostream&, const T&) {}
template <ll i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
  if (i) os << ",";
  os << get<i>(t);
  print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  os << "{";
  print_tuple<0, tuple<Args...>, Args...>(os, t);
  return os << "}";
}
void print(ll x, ll suc = 1) {
  cout << x;
  if (suc == 1) cout << endl;
  if (suc == 2) cout << " ";
}
vi readvi(ll n, ll off = 0) {
  vi v(n);
  for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;
  return v;
}
template <class T>
void print(const vector<T>& v, ll suc = 1) {
  for (ll i = ll(0); i < ll(v.size()); i++)
    print(v[i], i == ll(v.size()) - 1 ? suc : 2);
}
string readString() {
  string s;
  cin >> s;
  return s;
}
template <class T>
T sq(const T& t) {
  return t * t;
}
void yes(bool ex = true) {
  cout << "Yes" << endl;
  if (ex) exit(0);
}
void no(bool ex = true) {
  cout << "No" << endl;
  if (ex) exit(0);
}
const ll infLL = LLONG_MAX / 3;
const ll inf = infLL;
ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
ll popcount(signed t) { return __builtin_popcount(t); }
ll popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(ll i) { return i && (i & -i) == i; }
bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }
template <class T, class F>
struct SegTree {
  vc<T> buf;
  ll s;
  const F f;
  const T g;
  SegTree(const vc<T>& d, F ff, T gg) : f(ff), g(gg) {
    ll n = d.size();
    s = 1;
    while (s < n) s *= 2;
    buf.resize(s * 2, g);
    for (ll i = ll(0); i < ll(n); i++) buf[i + s] = d[i];
    for (ll i = ll(s) - 1; i >= 1; i--) u(i);
  }
  void u(ll i) { buf[i] = f(buf[i * 2], buf[i * 2 + 1]); }
  void set(ll i, T t) {
    i += s;
    buf[i] = t;
    while (i >>= 1) u(i);
  }
  T get(ll second, ll e, ll l, ll r, ll i) {
    if (e <= l || r <= second) return g;
    if (second <= l && r <= e) return buf[i];
    ll m = (l + r) / 2;
    return f(get(second, e, l, m, i * 2), get(second, e, m, r, i * 2 + 1));
  }
  T get(ll second, ll e) { return get(second, e, 0, s, 1); }
};
template <class T, class F>
SegTree<T, F> segtree(const vc<T>& d, F f, T g) {
  return SegTree<T, F>(d, f, g);
}
struct W {
  vi x1, x2, y1, y2, as, hs, hxs;
  W() : as{0}, hs{0}, hxs{0} {}
  void push(ll first, ll second, ll c, ll d) {
    void(0);
    x1.push_back(first);
    x2.push_back(second);
    y1.push_back(c);
    y2.push_back(d);
    as.push_back(as.back() + (d - c) * (second - first));
    hs.push_back(hs.back() + (d - c));
    hxs.push_back(hxs.back() + (d - c) * second);
  }
  ll get(ll x, ll y) {
    ll s = upper_bound(y2.begin(), y2.end(), y) - y2.begin();
    ll res = 0;
    if (s < ll(x1.size()))
      res += max(y - y1[s], ll(0)) * max(x2[s] - max(x, x1[s]), ll(0));
    ll r = min(ll(lower_bound(x1.begin(), x1.end(), x) - x1.begin()), s);
    res += as[s] - as[r];
    ll q = min(ll(lower_bound(x2.begin(), x2.end(), x) - x2.begin()), s);
    res += hxs[r] - hxs[q] - x * (hs[r] - hs[q]);
    return res;
  }
};
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n = read();
  vc<pi> org(n + 2);
  for (ll i = ll(0); i < ll(n + 2); i++) org[i] = pi(-1 - i, i);
  auto seg = segtree(
      org, [](pi first, pi second) { return min(first, second); }, pi(inf, -1));
  vc<W> ws(n + 2);
  set<ll> vis;
  for (ll i = ll(0); i < ll(n + 2); i++) vis.insert(i);
  struct R {
    ll l, r, t;
  };
  vc<R> rs(n + 2, {-1, -1, -1});
  ll ans = 0;
  vi raw;
  for (ll i = ll(0); i < ll(n); i++) {
    ll first = (read() + ans) % (n + 1), l = (read() + ans) % (i + 1),
       r = (read() + ans) % (i + 1), k = (read() + ans) % (n + 1);
    if (l > r) swap(l, r);
    r++;
    void(0);
    void(0);
    void(0);
    void(0);
    raw.push_back(first);
    void(0);
    const auto cut = [&](ll x) {
      if (rs[x].l < rs[x].r) {
        void(0);
        ws[x].push(rs[x].l, rs[x].r, rs[x].t, i);
        rs[x] = {-1, -1, -1};
      }
    };
    auto itr = vis.find(first);
    if (itr != vis.end()) {
      cut(first);
      ll p = *vis.erase(itr);
      cut(p);
      org[first].first = i;
      seg.set(first, org[first]);
      while (p > first) {
        ll q = seg.get(0, p).second;
        void(0);
        vis.insert(q);
        rs[p] = {org[p].first + 1, org[q].first + 1, i};
        p = q;
      }
    } else {
      org[first].first = i;
      seg.set(first, org[first]);
    }
    vis.insert(0);
    cut(0);
    rs[0] = {org[0].first + 1, i + 1, i};
    ans = ws[k].get(l, r);
    ans += max(r - rs[k].t, ll(0)) * max(rs[k].r - max(rs[k].l, l), ll(0));
    print(ans);
  }
}
