#include <bits/stdc++.h>
#include "code.h"
using namespace std;
int N, Q;
map <array <int, 3>, int> MAP;
int Query(int a, int b, int c)
{
  array <int, 3> arr = {a, b, c};
  if(MAP.find(arr) != MAP.end()) return MAP[arr];
  return MAP[arr] = Pitaj(a, b, c);
}
vector <pair <int, int>> ZapisiTacke(int n)
{
  N = n;
  vector <pair <int, int>> V(N + 1);
  V[1] = {0, 0};
  for(int i = 2; i <= N; i++) V[i] = {N - i, i - 2};
  return V;
}
vector <int> Resi(int n, int q)
{
  int p1 = -1;
  for(int i = 3, j; i <= N; i += 3)
  {
    if(!Query(i - 2, i - 1, i)) continue;
    if(i == 3) j = 4;
    else j = i - 3;
    if(!Query(i - 2, i - 1, j)) p1 = i;
    else if(!Query(i - 2, j, i)) p1 = i - 1;
    else p1 = i - 2;
  }
  if(p1 == -1)
  {
    if((N % 3) == 1) p1 = N;
    else
    {
      if(!Query(1, 2, N - 1)) p1 = N;
      else p1 = N - 1;
    }
  }
  vector <int> I(N + 1), V(N);
  for(int i = 0; i < N; i++) V[i] = i + 1;
  swap(V[p1 - 1], V[0]);
  sort(next(V.begin()), V.end(), [&](int i, int j){
    return Query(p1, i, j) > 0;
  });
  for(int i = 0; i < N; i++) I[V[i]] = i + 1;
  return I;
}