#include <bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
typedef pair<int,int> t;
vector<t> tacke;

vector<t> ZapisiTacke(int N){
    tacke.resize(N+1);
    tacke[1] = {0, 1};

    for(int i = 2; i <= N; i++){
        tacke[i] = {i, 0};
    }

    return tacke;
}

vector<int> Resi(int N, int Q){

    auto add = [&](int x, int a){
        if((x+a)%N == 0) return N;
        return (x+a)%N;
    };


    int doktor;
    for(int i = 1; i <= N; i++){
        int a = i, b = add(i, 1), c = add(i, 2);
        if(Pitaj(a,b,c) != 0){
            int nt = add(c, 1);
            if(Pitaj(a, b, nt) == 0) doktor = c;
            else if(Pitaj(a, nt, c) == 0) doktor = b;
            else doktor = a;

            break;
        }
    }
    vector<int> perm(N+1);

    perm[doktor] = 1;
    for(int i = 1; i <= N; i++){
        if(i == doktor) continue;
        int pos = 0;
        for(int j = 1; j <= N; j++){
            if(j == doktor || j == i) continue;
            int d = Pitaj(doktor, i, j);
            if(d < 0) pos++;
        }

        perm[i] = pos+2;
    }

    return perm;
}