#include <iostream>
#include <cstdio>
using namespace std;
#define maxN (1<<20)
long n,i,_n;
pair< long , pair<long,long> > Q[maxN];
long qA[maxN],qB[maxN],qC[maxN];
long a,b,c;
long col[maxN];
long wh [maxN];
long getNext(long x){
if(!col[x]) return x;
wh[x] = getNext( wh[x] );
return wh[x];
}
int main()
{
freopen("curcubeu.in","r",stdin);
freopen("curcubeu.out","w",stdout);
scanf("%ld %ld %ld %ld",&n,&qA[1],&qB[1],&qC[1]);
_n = n;
for(i=2;i<n;i++){
qA[i] = (1LL*qA[i-1]*i)%n;
qB[i] = (1LL*qB[i-1]*i)%n;
qC[i] = (1LL*qC[i-1]*i)%n;
}
for(i=1;i<n;i++) wh[i] = i+1;
for(;--n>0;){
a = qA[n];
b = qB[n];
c = qC[n];
if(a>b) swap(a,b);
//! solve...
long s = a,d=b,what=c;
long _fin=d+1,_s;
while(s<=d){
if(!col[s]) col[s] = what;
_s = s;
s = getNext(s);
wh[_s] = _fin;
}
}
n = _n;
for(i=1;i<n;i++) printf("%ld\n",col[i]);
return 0;
}