Ilshat is a software engineer working on efficient data structures. One day he invented a new data structure. This data structure can store a set of non-negative $n$-bit integers, where $n$ is a power of two. That is, $n = 2^b$ for some non-negative integer $b$.

The data structure is initially empty. A program using the data structure has to follow the following rules:

* The program can add elements that are $n$-bit integers into the data structure, one at a time, by using the function add\_element(x). If the program tries to add an element that is already present in the data structure, nothing happens.
* After adding the last element the program should call the function compile\_set() exactly once.
* Finally, the program may call the function check\_element(x) to check whether the element $x$ is present in the data structure. This function may be used multiple times.

When Ilshat first implemented this data structure, he made a bug in the function compile\_set(). The bug reorders the binary digits of each element in the set in the same manner. Ilshat wants you to find the exact reordering of digits caused by the bug.

Formally, consider a sequence $p_0, \ldots, p_{n - 1}$ in which every number from $0$ to $n - 1$ appears exactly once. We call such a sequence a permutation. Consider an element of the set, whose digits in binary are $a_0, \ldots, a_{n - 1}$ (with $a_0$ being the most significant bit). When the function compile\_set() is called, this element is replaced by the element $a_{p_0}, a_{p_1}, \ldots, a_{p_{n - 1}}$.

The same permutation $p$ is used to reorder the digits of every element. Any permutation is possible, including the possibility that $p_i = i$ for each $0 \le i \le n - 1$.

For example, suppose that $n = 4$, $p = [2, 1, 3, 0]$, and you have inserted into the set integers whose binary representations are 0000, 1100 and 0111. Calling the function compile\_set changes these elements to 0000, 0101 and 1110, respectively.

Your task is to write a program that finds the permutation $p$ by interacting with the data structure. It should (in the following order):

1. choose a set of $n$-bit integers,
2. insert those integers into the data structure,
3. call the function compile\_set to trigger the bug,
4. check the presence of some elements in the modified set,
5. use that information to determine and return the permutation $p$.

Note that your program may call the function compile\_set only once.

In addition, there is a limit on the number of times your program calls the library functions. Namely, it may

* call add\_element at most $w$ times ($w$ is for "writes"),
* call check\_element at most $r$ times ($r$ is for "reads").

Implementation details

You should implement one function (method):

* int[] restore\_permutation(int n, int w, int r)
  + n: the number of bits in the binary representation of each element of the set (and also the length of $p$).
  + w: the maximum number of add\_element operations your program can perform.
  + r: the maximum number of check\_element operations your program can perform.
  + the function should return the restored permutation $p$.

Library functions

In order to interact with the data structure, your program should use the following three functions (methods):

* void add\_element(string x)

  This function adds the element described by x to the set.

  + x: a string of '0' and '1' characters giving the binary representation of an integer that should be added to the set. The length of x must be $n$.

* void compile\_set()

  This function must be called exactly once. Your program cannot call add\_element() after this call. Your program cannot call check\_element() before this call.

* boolean check\_element(string x)

  This function checks whether the element x is in the modified set.

  + x: a string of '0' and '1' characters giving the binary representation of the element that should be checked. The length of x must be $n$.
  + returns true if element x is in the modified set, and false otherwise.

Note that if your program violates any of the above restrictions, its grading outcome will be "Wrong Answer".

For all the strings, the first character gives the most significant bit of the corresponding integer.

The grader fixes the permutation $p$ before the function restore\_permutation is called.

Please use the provided template files for details of implementation in your programming language.

Input

The sample grader reads the input in the following format:

* line 1: integers $n$, $w$, $r$,
* line 2: $n$ integers giving the elements of $p$.

Output

One string — the return value of restore\_permutation.

Scoring

|  |  |  |
| --- | --- | --- |
| Subtask | Points | Additional Input Constraints |
| 1 | 20 | $n = 8$, $w = 256$, $r = 256$, $p_i \neq i$ for at most 2 indices $i$ ($0 \le i \leq n - 1$) |
| 2 | 18 | $n = 32$, $w = 320$, $r = 1024$ |
| 3 | 11 | $n = 32$, $w = 1024$, $r = 320$ |
| 4 | 21 | $n = 128$, $w = 1792$, $r = 1792$ |
| 5 | 30 | $n = 128$, $w = 896$, $r = 896$ |

Example

Input

```
4 16 16
2 1 3 0
```

Output

```
2 1 3 0
```

Note

Example

The grader makes the following function call:

* restore\_permutation(4, 16, 16). We have $n = 4$ and the program can do at most $16$ "writes" and $16$ "reads".

The program makes the following function calls:

* add\_element("0001")
* add\_element("0011")
* add\_element("0100")
* compile\_set()
* check\_element("0001") returns false
* check\_element("0010") returns true
* check\_element("0100") returns true
* check\_element("1000") returns false
* check\_element("0011") returns false
* check\_element("0101") returns false
* check\_element("1001") returns false
* check\_element("0110") returns false
* check\_element("1010") returns true
* check\_element("1100") returns false

Only one permutation is consistent with these values returned by check\_element(): the permutation $p = [2, 1, 3, 0]$. Thus, restore\_permutation should return [2, 1, 3, 0].

#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cstdlib>
#include <iostream>
#include "messy.h"

using namespace std;

namespace helper {

    set<string> set_;
    bool compiled = false;
    int n;
    vector<int> p;
    int w;
    int r;

    int read_int() {
        int x;
        cin >> x;
        return x;
    }

}

using namespace helper;

// A convenience function.
int get_p(int i) {
    int ret = p[i];
    return ret;
}

int main() {
    n = read_int();
    w = read_int();
    r = read_int();
    p = vector<int>(n);
    for (int i = 0; i < n; i++) {
        p[i] = read_int();
    }
    vector<int> answer = restore_permutation(n, w, r);

    if (answer.size() != n) {
        printf("WA\n");
        return 0;
    }

    printf("%d", answer[0]);

    for (int i = 1; i < n; i++) {
        printf(" %d", answer[i]);
    }
    printf("\n");
    return 0;
}

void wa() {
    printf("WA\n");
    exit(0);
}

bool check(const string& x) {
    if ((int)x.length() != n) {
        return false;
    }
    for (int i = 0; i < n; i++) {
        if (x[i] != '0' && x[i] != '1') {
            return false;
        }
    }
    return true;
}

void add_element(string x) {
    if (--w < 0 || compiled || !check(x)) {
        wa();
    }
    set_.insert(x);
}

bool check_element(string x) {
    if (--r < 0 || !compiled || !check(x)) {
        wa();
    }
    return set_.count(x);
}

void compile_set() {
    if (compiled) {
        wa();
    }
    compiled = true;
    set<string> compiledSet;
    string compiledElement = string(n, ' ');
    for (set<string>::iterator it = set_.begin(); it != set_.end(); it++) {
        string s = *it;
        for (int i = 0; i < n; i++) {
            compiledElement[i] = s[get_p(i)];
        }
        compiledSet.insert(compiledElement);
    }
    set_ = compiledSet;
}

#include <vector>

#include "messy.h"

std::vector<int> restore_permutation(int n, int w, int r) {
    add_element("0");
    compile_set();
    check_element("0");
    return std::vector<int>();
}

#pragma once

#include <vector>
#include <string>

void add_element(std::string x);
bool check_element(std::string x);
void compile_set();

std::vector<int> restore_permutation(int n, int w, int r);


Amina has six coins, numbered from $1$ to $6$. She knows that the coins all have different weights. She would like to order them according to their weight. For this purpose she has developed a new kind of balance scale.

A traditional balance scale has two pans. To use such a scale, you place a coin into each pan and the scale will determine which coin is heavier.

Amina's new scale is more complex. It has four pans, labeled $A$, $B$, $C$, and $D$. The scale has four different settings, each of which answers a different question regarding the coins. To use the scale, Amina must place exactly one coin into each of the pans $A$, $B$, and $C$. Additionally, in the fourth setting she must also place exactly one coin into pan $D$.

The four settings will instruct the scale to answer the following four questions:

1. Which of the coins in pans $A$, $B$ and $C$ is the heaviest?
2. Which of the coins in pans $A$, $B$ and $C$ is the lightest?
3. Which of the coins in pans $A$, $B$ and $C$ is the median? (This is the coin that is neither the heaviest nor the lightest of the three.)
4. Among the coins in pans $A$, $B$ and $C$, consider only the coins that are heavier than the coin on pan $D$. If there are any such coins, which of these coins is the lightest? Otherwise, if there are no such coins, which of the coins in pans $A$, $B$ and $C$ and is the lightest?

Write a program that will order Amina's six coins according to their weight. The program can query Amina's scale to compare weights of coins. Your program will be given several test cases to solve, each corresponding to a new set of six coins.

Your program should implement the functions init and orderCoins. During each run of your program, the grader will first call init exactly once. This gives you the number of test cases and allows you to initialize any variables. The grader will then call orderCoins() once per test case.

* void init(int T)
  + $T$: The number of test cases your program will have to solve during this run. $T$ is an integer from the range $1,\dots,18$.
  + This function has no return value.
* void orderCoins()
  + This function is called exactly once per test case.
  + The function should determine the correct order of Amina's coins by calling the grader functions getHeaviest(), getLightest(), getMedian(), and/or getNextLightest().
  + Once the function knows the correct order, it should report it by calling the grader function answer().
  + After calling answer(), the function orderCoins() should return. It has no return value.

You may use the following grader functions in your program:

* answer(W) — your program should use this function to report the answer that it has found.
  + $W$: An array of length $6$ containing the correct order of coins. $W[0]$ through $W[5]$ should be the coin numbers (i.e., numbers from $1$ to $6$) in order from the lightest to the heaviest coin.
  + Your program should only call this function from orderCoins(), once per test case.
  + This function has no return value.
* getHeaviest(A, B, C), getLightest(A, B, C), getMedian(A, B, C) — these correspond to settings $1$, $2$ and $3$ respectively for Amina's scale.
  + $A, B, C$: The coins that are put in pans $A$, $B$ and $C$, respectively. $A$, $B$, and $C$ should be three distinct integers, each between $1$ and $6$ inclusive.
  + Each function returns one of the numbers $A$, $B$, and $C$: the number of the appropriate coin. For example, getHeaviest(A, B, C) returns the number of the heaviest of the three
  + given coins.
* getNextLightest(A, B, C, D) — this corresponds to setting 4 for Amina's scale
  + $A, B, C, D$: The coins that are put in pans $A$, $B$, $C$, and $D$, respectively. $A$, $B$, $C$, and $D$ should be four distinct integers, each between $1$ and $6$ inclusive.
  + The function returns one of the numbers $A$, $B$, and $C$: the number of the coin selected by the scale as described above for setting $4$. That is, the returned coin is the lightest amongst those coins on pans $A$, $B$, and $C$ that are heavier than the coin in pan $D$; or, if none of them is heavier than the coin on pan $D$, the returned coin is simply the lightest of all three coins on pans $A$, $B$, and $C$.

Input

The sample grader reads input in the following format:

* line $1$: $T$ — the number of test cases
* each of the lines from $2$ to $T + 1$: a sequence of $6$ distinct numbers from $1$ to $6$ the coins from the lightest to the heaviest.

Scoring

There are no subtasks in this problem. Instead, your score will be based on how many weighings (total number of calls to grader functions getLightest(), getHeaviest(), getMedian() and/or getNextLightest()) your program makes.

Your program will be run multiple times with multiple test cases in each run. Let $r$ be the number of runs of your program. This number is fixed by the test data. If your program does not order the coins correctly in any test case of any run, it will get $0$ points. Otherwise, the runs are scored individually as follows.

Let $Q$ be the smallest number such that it is possible to sort any sequence of six coins using $Q$ weighings on Amina's scale. To make the task more challenging, we do not reveal the value of $Q$ here.

Suppose the largest number of weighings amongst all test cases of all runs is $Q + y$ for some integer $y$. Then, consider a single run of your program.

Then, the score for this run will be $\frac{100}{r(y / 2.5 + 1)}$, rounded down to two digits after the decimal point.

In particular, if your program makes at most $Q$ weighings in each test case of every run, you will get $100$ points.

On the original contest, scoring was a bit different to award solutions, which are good on average. It's not implemented here.

Example

Input

```
2
1 2 3 4 5 6
3 4 6 2 1 5
```

Output

```
1 2 3 4 5 6 6
3 4 6 2 1 5 6
```

Note

Suppose the coins are ordered $3\ 4\ 6\ 2\ 1\ 5$ from the lightest to the heaviest.

|  |  |  |
| --- | --- | --- |
| Function call | Returns | Explanation |
| getMedian(4, 5, 6) | 6 | Coin $6$ is the median among coins $4$, $5$, and $6$. |
| getHeaviest(3, 1, 2) | 1 | Coin $1$ is the heaviest among coins $1$, $2$, and $3$. |
| getNextLightest(2, 3, 4, 5) | 3 | Coins $2$, $3$, $4$ and are all lighter than coin $5$, so the lightest among them $(3)$ is returned. |
| getNextLightest(1, 6, 3, 4) | 6 | Coins $1$ and $6$ are both heavier than coin $4$. Among coins $1$ and $6$, coin $6$ is the lightest one. |
| getHeaviest(3, 5, 6) | 5 | Coin $5$ is the heaviest among coins $3$, $5$ and $6$. |
| getMedian(1, 5, 6) | 1 | Coin $1$ is the median among coins $1$, $5$ and $6$. |
| getMedian(2, 4, 6) | 6 | Coin $6$ is the median among coins $2$, $4$ and $6$. |
| answer([3, 4, 6, 2, 1, 5]) |  | The program found the right answer fot this test case. |

#include "graderlib.c"

int main() {

    int T, i;

    T = _getNumberOfTests();
    init(T);

    for (i = 1; i <= T; i++) {
        _initNewTest();
        orderCoins();
    }

    return 0;
}

#include "scales.h"

void init(int T) {
    /* ... */
}

void orderCoins() {
    /* ... */
    int W[] = {1, 2, 3, 4, 5, 6};
    answer(W);
}

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "scales.h"

#define _MAXN 6
#define _MAX_ANSWER_CALLS 1

static int _realC[_MAXN];
static int _ind[_MAXN];
static int _numQueries;
static int _numAnswerCalls;
static FILE * _f;
static FILE * _of;

static int _getNumberOfTests() {
    int T, ret;

    _f = stdin;
    _of = stdout;

    ret = fscanf(_f, "%d", &T);
    assert(ret == 1);
    return T;
}

static void _initNewTest() {
    int i, ret;

    for (i = 0; i < _MAXN; i++) {
        ret = fscanf(_f, "%d", &_realC[i]);
        assert(ret == 1);
        _realC[i]--;
        _ind[_realC[i]] = i;
    }

    _numQueries = 0;
    _numAnswerCalls = 0;
}

void answer(int W[]) {
    int i;

    _numAnswerCalls++;
    if (_numAnswerCalls > _MAX_ANSWER_CALLS)
        return;

    // W[i] = coin number at position i+1 (1-indexed coin)
    // _realC[i] = coin number at position i (0-indexed)
    int correct = 1;
    for (i = 0; i < 6; i++) {
        if (W[i] != _realC[i] + 1) {
            correct = 0;
            break;
        }
    }

    if (correct) {
        fprintf(_of, "OK %d\n", _numQueries);
    } else {
        fprintf(_of, "WA\n");
    }
}

static void _checkQuery(int A, int B, int C, int D) {
    if (D == -1) {
        if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6)
            assert(0);
        if (A == B || B == C || A == C)
            assert(0);
    }
    else {
        if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6 || D < 1 || D > 6)
            assert(0);
        if (A == B || A == C || A == D || B == C || B == D || C == D)
            assert(0);
    }
}

int getMedian(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[B] < _ind[A] && _ind[A] < _ind[C])
        return A + 1;

    if (_ind[C] < _ind[A] && _ind[A] < _ind[B])
        return A + 1;

    if (_ind[A] < _ind[B] && _ind[B] < _ind[C])
        return B + 1;

    if (_ind[C] < _ind[B] && _ind[B] < _ind[A])
        return B + 1;

    return C + 1;
}

int getHeaviest(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[A] > _ind[B] && _ind[A] > _ind[C])
        return A + 1;

    if (_ind[B] > _ind[A] && _ind[B] > _ind[C])
        return B + 1;

    return C + 1;
}

int getLightest(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[A] < _ind[B] && _ind[A] < _ind[C])
        return A + 1;

    if (_ind[B] < _ind[A] && _ind[B] < _ind[C])
        return B + 1;

    return C + 1;
}

int getNextLightest(int A, int B, int C, int D) {
    int allLess = 1;

    _numQueries++;
    _checkQuery(A, B, C, D);

    A--; B--; C--; D--;

    if (_ind[A] > _ind[D] || _ind[B] > _ind[D] || _ind[C] > _ind[D])
        allLess = 0;

    if (allLess == 1) {
        if (_ind[A] < _ind[B] && _ind[A] < _ind[C])
            return A + 1;

        if (_ind[B] < _ind[A] && _ind[B] < _ind[C])
            return B + 1;

        return C + 1;
    }

    if (_ind[A] > _ind[D]) {
        if ((_ind[A] < _ind[B] || _ind[B] < _ind[D]) && (_ind[A] < _ind[C] || _ind[C] < _ind[D]))
            return A + 1;
    }

    if (_ind[B] > _ind[D]) {
        if ((_ind[B] < _ind[A] || _ind[A] < _ind[D]) && (_ind[B] < _ind[C] || _ind[C] < _ind[D]))
            return B + 1;
    }

    return C + 1;
}

#ifndef __SCALES_H__
#define __SCALES_H__

#ifdef __cplusplus
extern "C" {
#endif

void init(int T);
void orderCoins();
void answer(int W[]);

int getMedian(int A, int B, int C);
int getHeaviest(int A, int B, int C);
int getLightest(int A, int B, int C);
int getNextLightest(int A, int B, int C, int D);

#ifdef __cplusplus
}
#endif

#endif /* __SCALES_H__ */