Under construction

Still being built. Things may change

Henry Porter and the Palindromic Radius

Time limit25sMemory limit512 MB

Summary
Given the palindromic radius at every position of an unknown binary string, the task is to list all binary strings that produce exactly those radii.
Level

Medium7 of 10

Topics
String matching, String, Implementation
Solved
No attempts yet

Problem

A young wizard, Henry Porter, has just received sad news. His eldest relative, uncle Markus Radius Palindromus Black, has passed away. Uncle Markus was known as an eccentric person who used complicated binary magic, and he was also very, very rich.

Black's will states that Henry should inherit his mysterious chamber of treasures. To enter and claim it, however, the young wizard must say the right password HH, a word of length nn consisting of characters 0 and 1. Uncle Markus did not tell Henry the password. Instead, for every x=1,2,…,nx = 1, 2, \ldots, n, he computed the palindromic radius pxp_x, the largest integer such that the word H[x−px..x+px]H[x - p_x .. x + p_x] of length 2px+12p_x + 1 centered at H[x]H[x] exists and is a palindrome. Henry only received the values p1,…,pnp_1, \ldots, p_n. For example, if the password was 10111010, Henry would get the sequence (0,1,0,3,0,1,1,0)(0, 1, 0, 3, 0, 1, 1, 0).

Henry would rather Uncle Markus not test his algorithmic skills from beyond the grave, but he has good friends who can help. Given the sequence left in the will, determine all possible passwords that match it. Since the will is battered and stained, it may happen that there is no solution at all.

Input

The first line contains the number of test cases zz (1≤z≤2000001 \le z \le 200000). Each test case consists of two lines. The first line contains a single integer nn, the length of both the password and Black's sequence (2≤n≤10000002 \le n \le 1000000). The second line contains nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n (0≤pi≤n0 \le p_i \le n), the palindromic radii. The sum of nn over all test cases does not exceed 5×1075 \times 10^7.

Output

For every test case, first output the number kk of possible passwords. If k>0k > 0, output the kk passwords on the next kk lines as {0,1}\{0,1\}-sequences in lexicographic order. You may assume that kk does not exceed 100.

Examples1

  1. Example 1

    Input
    1
    8
    0 1 0 3 0 1 1 0
    
    Expected output
    4
    00010000
    01000101
    10111010
    11101111