#include <bits/stdc++.h>
using namespace std;
ifstream f("curcubeu.in");
ofstream g("curcubeu.out");
const int Max = 1e6 + 1;
void nos()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
#define color first
#define time second
int n,a,b,c;
pair < int, int > tree[4*Max];
int rev[Max];
int timp;
void color_layer(int where, int left, int right, int left_limit, int right_limit, int color)
{
if(left_limit <= left and right <= right_limit)
{
tree[where].color = color;
tree[where].time = timp;
return;
}
int mid = (left + right) / 2;
if(left_limit <= mid)
color_layer(2*where,left,mid,left_limit,right_limit,color);
if(mid + 1 <= right_limit)
color_layer(2*where+1,mid+1,right,left_limit,right_limit,color);
}
void get_rev(int where, int left, int right)
{
if(left == right)
{
rev[left] = where;
return;
}
int mid = (left + right) / 2;
get_rev(2*where,left,mid);
get_rev(2*where+1,mid+1,right);
}
void read()
{
f>>n>>a>>b>>c;
}
pair < int, int > ans;
void ask(int where)
{
if(tree[where].time > ans.time)
ans = tree[where];
if(where!=1)
ask(where/2);
}
void solve()
{
get_rev(1,1,n-1);
int i;
timp = 1;
color_layer(1,1,n-1,min(a,b),max(a,b),c);
for(i=2; i<n; i++)
{
timp = i;
a = (a * i) % n;
b = (b * i) % n;
c = (c * i) % n;
color_layer(1,1,n-1,min(a,b),max(a,b),c);
// cout<<a<<' '<<b<<' '<<c<<'\n';
}
for(i=1; i<n; i++)
{
ans.color = 0;
ans.time = 0;
ask(rev[i]);
g<<ans.color<<'\n';
}
}
void restart()
{
}
int32_t main()
{
nos();
read();
solve();
restart();
return 0;
}