#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int MAXN = 1000005;
int A[MAXN], B[MAXN], C[MAXN];
int color[MAXN];
int next_pos[MAXN];
int find_next(int x) {
int root = x;
while (next_pos[root] != root) {
root = next_pos[root];
}
while (next_pos[x] != root) {
int aux = next_pos[x];
next_pos[x] = root;
x = aux;
}
return root;
}
int main() {
ifstream cin("curcubeu.in");
ofstream cout("curcubeu.out");
int n;
if (!(cin >> n >> A[1] >> B[1] >> C[1])) return 0;
for (int i = 2; i <= n - 1; ++i) {
A[i] = (1LL * A[i - 1] * i) % n;
B[i] = (1LL * B[i - 1] * i) % n;
C[i] = (1LL * C[i - 1] * i) % n;
}
for (int i = 1; i <= n; ++i) {
next_pos[i] = i;
}
for (int i = n - 1; i >= 1; --i) {
int left = min(A[i], B[i]);
int right = max(A[i], B[i]);
int pos = find_next(left);
while (pos <= right) {
color[pos] = C[i];
next_pos[pos] = pos + 1;
pos = find_next(pos);
}
}
for (int i = 1; i <= n - 1; ++i) {
cout << color[i] << "\n";
}
return 0;
}