#include <bits/stdc++.h>
using namespace std;
int vf[256], a[10000005], temp[10000005];
int32_t main(void){
ofstream cout("radixsort.out");
ifstream cin("radixsort.in");
int n;
cin >> n;
long int A,b,c;
cin >> A >> b >> c;
a[1] = b;
for(int i = 2;i <= n;i++){
a[i] = (1LL * A * a[i - 1] + b) % c;
}
for(int bucket = 0; bucket < 4; bucket++){
int shift = 8 * bucket;
for(int i = 0; i <= 256; i++){
vf[i] = 0;
}
for(int i = 1;i <= n;i++){
vf[(a[i] >> shift) & 255]++; /// sortam dupa bucket ul cifra
}
for(int i = 1 ;i <= 256;i++){
vf[i] += vf[i-1];
}
for(int i = n; i >= 1;i--){
temp[vf[(a[i] >> shift) & 255]--] = a[i];
}
for(int i = 1;i <= n;i++){
a[i] = temp[i];
}
}
for(int i = 1;i <= n;i++){
cout << a[i] << ' ';
}
}