// https://infoarena.ro/problema/curcubeu
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int NMAX=1e6+8;
long long n;
long long a[NMAX],b[NMAX],c[NMAX];
int ans[NMAX];
struct dsu {
vector<int> t, sz, dr;
dsu(int n) : t(n+8), sz(n+8), dr(n+8) {
for(int i=1; i<=n; i++) {
t[i]=i;
sz[i]=1;
dr[i]=i+1;
}
}
int root(int x) {
if(x==t[x]) {
return x;
}
return t[x]=root(t[x]);
}
bool unite(int x,int y) {
x=root(x);
y=root(y);
if(x==y) {
return 0;
}
if(sz[x]<sz[y]) {
swap(x,y);
}
sz[x]+=sz[y];
t[y]=x;
dr[x]=max(dr[x],dr[y]);
return 1;
}
};
int main() {
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> a[1] >> b[1] >> c[1];
for(long long 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;
}
dsu v(n);
for(int i=n-1; i>=1; i--) {
int pos=min(a[i],b[i]);
int dr=max(a[i],b[i]);
if(ans[pos]!=0) {
pos=v.dr[v.root(pos)];
}
int st=pos;
while(st<=dr) {
ans[st]=c[i];
if(st-1>=1 && pos-1>=1) {
v.unite(st,pos-1);
}
st=v.dr[v.root(st)];
}
}
for(int i=1; i<n; i++) {
fout << ans[i] << "\n";
}
return 0;
}