This page is still under construction.

Parts of this page are still being built. What you see may change.

Sylvester construction

Time limit1sMemory limit128 MB

Summary
Given a Hadamard matrix built by the Sylvester doubling rule, print a small rectangular sub-matrix specified by its top-left corner.
Level

Medium7 of 10

Topics
Divide and conquer, Recursion, Bit manipulation, Math
Solved
No attempts yet

Problem

A Hadamard matrix of order nn is an n×nn \times n matrix whose entries are only 11 and −1-1, written HnH_n, satisfying HnHnT=nInH_n H_n^T = n I_n, where InI_n is the n×nn \times n identity matrix. A notable property of Hadamard matrices is that they attain the largest possible determinant among all n×nn \times n matrices whose entries lie in [−1,1][-1, 1]. Hadamard matrices are used in error-correcting codes and in weighing designs.

The Sylvester construction builds a Hadamard matrix of size 2n2n from HnH_n:

H2n=(HnHnHn−Hn)H_{2n} = \begin{pmatrix} H_n & H_n \\ H_n & -H_n \end{pmatrix}

For example,

H1=(1),H2=(111−1)H_1 = \begin{pmatrix} 1 \end{pmatrix}, \qquad H_2 = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}

and so on.

In this problem you must print a portion of a Hadamard matrix constructed in this way.

Input

The first number in the input is the number of test cases that follow. Each test case consists of five integers nn, xx, yy, ww, and hh. nn is a power of two with 1≤n≤2621 \le n \le 2^{62}. The pair (x,y)(x, y) is the upper-left corner of the sub-matrix to print, where xx is the column index and yy is the row index; ww and hh are its width and height. Coordinates are zero-based, so 0≤x,y<n0 \le x, y < n. The sub-matrix always fits entirely inside the full matrix, and 0<w,h≤200 < w, h \le 20. There are at most 10001000 test cases.

Output

For each test case, print the requested sub-matrix, with the entries in each row separated by single spaces. Print one blank line between the outputs of consecutive test cases.

Examples3

  1. Example 1

    Input
    3
    2 0 0 2 2
    4 1 1 3 3
    268435456 12345 67890 11 12
    
    Expected output
    1 1
    1 -1
    
    -1 1 -1
    1 -1 -1
    -1 -1 1
    
    1 -1 -1 1 1 -1 -1 1 1 -1 -1
    -1 -1 1 1 -1 -1 1 1 -1 -1 1
    1 1 1 -1 -1 -1 -1 1 1 1 1
    -1 1 -1 -1 1 -1 1 1 -1 1 -1
    1 -1 -1 -1 -1 1 1 1 1 -1 -1
    -1 -1 1 -1 1 1 -1 1 -1 -1 1
    -1 -1 -1 -1 -1 -1 -1 1 1 1 1
    1 -1 1 -1 1 -1 1 1 -1 1 -1
    -1 1 1 -1 -1 1 1 1 1 -1 -1
    1 1 -1 -1 1 1 -1 1 -1 -1 1
    -1 -1 -1 1 1 1 1 1 1 1 1
    1 -1 1 1 -1 1 -1 1 -1 1 -1
    
  2. Example 2

    Input
    1
    1 0 0 1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    4 0 0 4 4
    
    Expected output
    1 1 1 1
    1 -1 1 -1
    1 1 -1 -1
    1 -1 -1 1