#include <cassert>
#include <cstdio>
#include <ios>
#include <iostream>
#include <vector>
struct Update {
int start, end, color;
};
class RangePainter {
public:
RangePainter(int n) : components(n), colors(n) {
for (int i = 0; i < n; ++i) {
components[i].parent = components[i].end = i;
components[i].rank = 0;
}
}
void paint(int l, int r, int color) {
int prev_block = -1;
int i = l;
while (i <= r) {
const auto block = find(i);
if (colors[i] == 0) { // Can [color] ever be 0?
colors[i] = color;
}
if (prev_block != -1) {
join(prev_block, block);
}
i = components[block].end + 1;
prev_block = block;
}
}
const std::vector<int>& get_colors() const { return colors; }
private:
void join(int a, int b) {
a = find(a);
b = find(b);
if (a == b) {
return;
}
if (components[a].rank < components[b].rank) {
std::swap(a, b);
}
components[b].parent = a;
components[a].end = std::max(components[a].end, components[b].end);
components[a].rank += components[a].rank == components[b].rank;
}
int find(int x) {
return components[x].parent == x
? x
: (components[x].parent = find(components[x].parent));
}
struct Component {
int parent, rank;
int end;
};
std::vector<Component> components;
std::vector<int> colors;
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
assert(freopen("curcubeu.in", "r", stdin));
assert(freopen("curcubeu.out", "w", stdout));
int n;
std::cin >> n;
std::vector<Update> updates(n - 1);
std::cin >> updates[0].start >> updates[0].end >> updates[0].color;
for (int i = 1; i + 1 < n; ++i) {
updates[i].start = static_cast<int64_t>(i + 1) * updates[i - 1].start % n;
updates[i].end = static_cast<int64_t>(i + 1) * updates[i - 1].end % n;
updates[i].color = static_cast<int64_t>(i + 1) * updates[i - 1].color % n;
}
RangePainter painter(n);
for (int i = n - 2; i >= 0; i--) {
if (updates[i].start > updates[i].end) {
std::swap(updates[i].start, updates[i].end);
}
painter.paint(updates[i].start, updates[i].end, updates[i].color);
}
auto colors = painter.get_colors();
colors.erase(colors.begin());
for (int i = 0; i + 1 < n; i++) {
std::cout << colors[i] << "\n";
}
return 0;
}