QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#6214. Unbounded Words

الإحصائيات

For a word $S$, if there exists a length $l$ such that $0 < l < \text{length}(S)$ and the prefix of $S$ of length $l$ is equal to the suffix of $S$ of length $l$, JYY calls $S$ "bounded". For example, "aabaa" and "ababab" are both bounded strings. If a word does not have such an $l$, JYY calls it an "unbounded word".

Now consider all strings of length $N$ consisting only of the letters 'a' and 'b'. JYY wants to know:

(1) How many unbounded words are there in total? (2) Among these unbounded words, which one is the $K$-th smallest in lexicographical order?

Input

The input contains multiple test cases. The first line contains a positive integer $T$, representing the number of test cases. The next $T$ lines each contain two positive integers $N$ and $K$, representing a test case.

Output

For each test case, output two lines. The first line contains an integer representing the number of unbounded words of length $N$. The second line contains a string of length $N$ representing the $K$-th smallest unbounded word.

Constraints

For 20% of the data, $N \le 20$. For 100% of the data, $1 \le T \le 5$, $1 \le N \le 64$. The input guarantees that for any test case, the $K$-th smallest unbounded word always exists.

Examples

Input 1

5
5 1
5 2
5 3
5 4
5 5

Output 1

12
aaaab
12
aaabb
12
aabab
12
aabbb
12
ababb

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.