#include<bits/stdc++.h>
#define fore(start,i,end) for(int i = start; i <= end; i++)
#define dbg(x) #x << "=" << x << " "
#define dbg2(x,y) "{" << x << "," << y << "} "
#define dbg3(x,y,k) "{" << x << "," << y << "," << k << "} "
#define dbg4(x,y,k,j) "{" << x << "," << y << "," << k << " , " << j << "} "
#define ll long long
#define f1 first
#define f2 second
#define inf 1000000005
#define debug_st(st) if (true) {cout << #st << " : "; stack<int> s123; while (!s123.empty()) cout << s123.top() << " ", s123.pop(); cout << "\n";}
#define debug_a(a,n) cout << #a << " : "; for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << "\n";
#define debug_m(a,n,m) cout << #a << " :\n"; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) cout << a[i][j] << " "; cout << "\n"; }cout << "\n";
#define debug_v(v) cout << #v << " : "; for(auto k : v) cout << k << " "; cout << "\n";
#define debug_s(s) cout << #s << " : "; for (auto k : s) cout << k < " "; cout << "\n";
#define debug_s2(s) cout << #s << " : "; for(auto k : s) cout << dbg2((*k).first,(*k).second); cout << "\n";
#define nmax 1000005
using namespace std;
ifstream in("curcubeu.in");
//ofstream out("curcubeu.out");
int Height[nmax],root[nmax],dr[nmax],color[nmax],v[nmax],n;
struct querry
{
int a,b,c;
}q[nmax];
int Find(int x)
{
if (root[x] == 0) return x;
root[x] = Find(root[x]);
return root[x];
}
void join(int x, int y)
{
if (x == y) return;
x = Find(x);
y = Find(y);
if (x == y) return;
if (Height[y] > Height[x])
swap(y , x);
root[y] = x;
Height[x] = max(Height[x] , Height[y] + 1);
dr[x] = max(dr[x] , dr[y]);
}
void Update(int st, int dr2, int c)
{int i;
i = st;
while (i <= dr2)
{
if (v[i] == 0)
{
color[i] = c;
join(st , i);
v[i] = 1;
i++;
}
else if(v[i] == 1)
{
join(st , i);
i = dr[Find(i)] + 1;
}
}
if (v[st - 1] == 1) join(st - 1 , st);
if (v[dr2 + 1] == 1) join(st , dr2+ 1);
}
char outBuffer[0x61A80]; unsigned int p;
__attribute__((always_inline)) void write(unsigned int x)
{
unsigned int digits = x > 0x3B9AC9FF ? 0xA :
x > 0x5F5E0FF ? 0x9 :
x > 0x98967F ? 0x8 :
x > 0xF423F ? 0x7 :
x > 0x1869F ? 0x6 :
x > 0x270F ? 0x5 :
x > 0x3E7 ? 0x4 :
x > 0x63 ? 0x3 :
x > 0x9 ? 0x2 : 0x1;
for(unsigned int i = ~-digits; ~i; --i)
{
outBuffer[p + i] = x % 0xA + 0x30;
x = x / 0xA;
}
p = p + digits;
outBuffer[p++] = '\n';
if (p > 400000 - 100)
{
puts(outBuffer);
for (int i = 0; i <= p; i++)
{
outBuffer[i] = 0;
}
p = 0;
}
}
int main()
{int i,st,dr2,c;
in >> n >> q[1].a >> q[1].b >> q[1].c;
for (i = 1; i <= n; i++) dr[i] = i,color[i] = 0, v[i] = 0,Height[i] = 0;
n--;
for (i = 2; i <= n; i++)
{
q[i].a = (q[i - 1].a * i) % (n + 1);
q[i].b = (q[i - 1].b * i) % (n + 1);
q[i].c = (q[i - 1].c * i) % (n + 1);
}
for (i = n; i >= 1; i--)
{
st = min(q[i].a , q[i].b);
dr2 = max(q[i].a , q[i].b);
c = q[i].c;
Update(st , dr2 , c);
}
for (int i = 1; i <= n; i++)
{
write(color[i]);
}
puts(outBuffer);
}