#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> josip[1000];
int encode(int n, int x, int y) {
if (josip[1].empty()) {
vector<int> b = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
for (int i = 1; i <= 920; i++) {
josip[i] = b;
ranges::next_permutation(b);
}
}
for (int p = 0; p < 12; p++) {
if (josip[x][p] && !josip[y][p]) {
return p+1;
}
}
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> josip[1000];
int decode(int n, int q, int h) {
if (josip[1].empty()) {
vector<int> b = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
for (int i = 1; i <= 920; i++) {
josip[i] = b;
ranges::next_permutation(b);
}
}
return josip[q][h-1];
}