#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;
#define max 1000006
int a[max], b[max], c[max], d[max], v[max];
int n, m;
int findd (int x, int y)
{
if (v[x] != 0 || x > y){
return x;
}
v[x] = findd (x+1, y);
return v[x];
}
void unionn (int x, int y, int z)
{
while (x <= y){
while (v[x]){
x = v[x];
}
x = findd (x, y);
d[x] = z;
}
}
int main ()
{
freopen ("curcubeu.in", "r", stdin);
freopen ("curcubeu.out", "w", stdout);
srand (time (0));
scanf ("%d %d %d %d", &n, &a[1], &b[1], &c[1]);
for (int i=2; i<n; i++){
a[i] = (a[i-1] * i) % n;
b[i] = (b[i-1] * i) % n;
c[i] = (c[i-1] * i) % n;
}
for (int i=n-1; i>=1; i--){
if (a[i] > b[i]){
m = a[i];
a[i] = b[i];
b[i] = m;
}
unionn (a[i], b[i], c[i]);
}
for (int i=1; i<n; i++){
printf ("%d\n", d[v[i]]);
}
return 0;
}