#include <bits/stdc++.h>
#include "code.h"
using namespace std;

namespace {
    static vector<pair<int, int>> points;
    static vector<int> p;
    static int n;
    static int q;
    static int qt;
}
vector<pair<int, int>> ZapisiTacke(int n){
    vector<pair<int , int>> tacke(n+1);
    tacke[1] = {1 , 0};
    tacke[2] = {2 , 0};
    tacke[3] = {3 , 0};
    for(int i = 4; i<n; i++){
        tacke[i] = {i , 0};
    }
    tacke[n] = {n , 1};
//    cout<<"tacke\n";
//    for(int i = 1; i<n+1; i++){
//        cout<<tacke[i].first<<" "<<tacke[i].second<<"\n";
//    }
//    cout<<"kraj\n";

    return tacke;
}

int tacka = 0;

bool kkkomparator(int a , int b){
    int broj = Pitaj(a , b , tacka);
    if(broj == 1){
        //cout<<a<<" "<<b<<" "<<tacka<<" t\n";
        //dobar raspored:
        return true;
    }else if (broj == -1){
        //cout<<a<<" "<<b<<" "<<tacka<<" nt\n";
        return false;
    }else{
        //cout<<broj<<"molim?\n";
    }
}

vector<int> Resi(int n, int q){
    //cout<<Pitaj(3 , 2 , 1)<<"niger\n";
    vector<int> resenje(n-1);
    //pusback res
    int br = 0 , res = -1;
    for(int i = 1; i<=n - 2; i+=3){
        if(Pitaj(i , i+1 , i+2) != 0){
            br = i;
            break;
        }
    }
    if(br == 0){
        br = n-2;
    }

    if(br > 1){
        if(Pitaj(1 , br , br+1) == 0){
            res = br+2;
        }else if (Pitaj(1 , br , br+2) == 0){
            res = br+1;
        }else{
            res = br;
        }
    }else{
        if(Pitaj(4 , br , br+1) == 0){
            res = br+2;
        }else if (Pitaj(4 , br , br+2) == 0){
            res = br+1;
        }else{
            res = br;
        }
    }

    if(res == -1){
        while (true){
            res = res;
        }
    }

    int nesto = 1;
    for(int i = 0; i<n-1; i++){
        if(nesto == res) nesto++;
        resenje[i] = nesto;
        nesto++;
    }

    tacka = res;//tacka broj u permutaciji je N
    //cout<<res<<"\n";
    sort(resenje.begin() , resenje.end() , kkkomparator);

    //resenje.push_back(res);

    vector<int> rr(n+1);

    for(int i = 0; i<n-1; i++){
        rr[resenje[i]] = i+1;
    }
    rr[tacka] = n;

//    for(int i = 0; i<n-1 /*temp*/; i++){
//        rr[i+1] = resenje[i];
//    }
    return rr;
}