#include <bits/stdc++.h>
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
const int NMAX = 10000005;
int n;
long long a, b, c;
unsigned int arr[NMAX];
unsigned int output[NMAX];
unsigned int cnt[11];
void countSort(int p){
for(int i = 0 ; i < 10; i++)
cnt[i] = 0;
for (int i = 1; i <= n; i++)
cnt[(arr[i]/p)%10]++;
for (int i = 1; i < 10; i++)
cnt[i] += cnt[i-1];
for(int i = n ; i >= 1; i--){
output[cnt[(arr[i]/p)%10]] = arr[i];
cnt[(arr[i]/p)%10]--;
}
for(int i = 1; i <= n; i++)
arr[i] = output[i];
}
void radixSort(){
unsigned int Max = INT_MIN;
for(int i = 1; i <= n; i++)
Max = max(arr[i], Max);
int nrCif = 0;
while(Max){
Max /= 10;
nrCif++;
}
int p = 1;
for(int i = 1; i <= nrCif; i++){
countSort(p);
p*=10;
}
}
int main() {
fin>>n>>a>>b>>c;
for(int i = 1; i <= n ; i++)
arr[i] = (a * arr[i-1] + b) % c;
radixSort();
for(int i = 1; i <= n; i+=10)
fout<<arr[i]<<" ";
return 0;
}