#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int main() {
int n;
long long a, b, c;
fin >> n >> a >> b >> c;
vector<vector<pair<int, int>>> start_events(n + 1);
vector<int> end_pos(n);
for (int i = 1; i < n; ++i) {
int st = min(a, b);
int dr = max(a, b);
start_events[st].push_back({i, (int)c});
end_pos[i] = dr;
a = (a * (i + 1)) % n;
b = (b * (i + 1)) % n;
c = (c * (i + 1)) % n;
}
priority_queue<pair<int, int>> pq;
for (int i = 1; i < n; ++i) {
for (const auto& ev : start_events[i]) {
pq.push(ev);
}
while (!pq.empty() && end_pos[pq.top().second] < i) {
pq.pop();
}
if (!pq.empty()) {
fout << pq.top().first << '\n';
} else {
fout << 0 << '\n';
}
}
return 0;
}