#include "scales.h"
void init(int T) {
/* ... */
}
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
ll other(ll a, ll b) {
if (a > b) swap(a, b);
ll add = (a > 3) * 3;
if (a > 3) a -= 3, b -= 3;
if (a == 1 && b == 2) return 3 + add;
if (a == 1 && b == 3) return 2 + add;
return 1 + add;
}
void orderCoins() {
int w[] = {1, 2, 3, 4, 5, 6};
w[0] = getLightest(1, 2, 3), w[2] = getHeaviest(1, 2, 3);
w[1] = other(w[0], w[2]);
w[3] = getLightest(4, 5, 6);
w[5] = getHeaviest(4, 5, 6);
w[4] = other(w[3], w[5]);
vector<ll> a = {w[0], w[1], w[2]};
vector<ll> b = {w[3], w[4], w[5]};
auto insert = [&](ll x, ll p) {
a.push_back(0);
for (ll i = a.size() - 1; i > p; i--) {
a[i] = a[i - 1];
}
a[p] = x;
};
while (b.size()) {
auto x = b[0];
ll s = a.size();
bool p = max(max(a[s - 3], a[s - 2]), a[s - 1]) > 3;
auto res = getNextLightest(a[s - 3], a[s - 2], a[s - 1], x);
if (res == a[s - 3]) {
if (p) insert(s, x);
else {
if (getLightest(a[s - 3], a[s - 2], x) == x) insert(x, s - 3);
else insert(x, s);
}
}
else if (res == a[s - 2]) insert(x, s - 2);
else if (res == a[s - 1]) insert(x, s - 1);
b.erase(b.begin());
}
answer(w);
}