Fillomino

시간 제한1초메모리 제한1024 MB

요약
토러스 모양 n×m 격자를 주어진 크기의 연결된 세 영역으로 나누되 각 아들의 칸을 포함하도록 하고, 불가능하면 -1을 출력한다.
난이도

보통10점 중 7점

유형
그래프, BFS, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Prof. Pang is the king of Pangland. Pangland is a board with size n×mn\times m. The cell at the ii-th row and the jj-th column is denoted as cell (i,j)(i, j) for all 1≤i≤n,1≤j≤m1\le i\le n, 1\le j\le m. If two cells share an edge, they are connected. The board is toroidal, that is, cell (1,y)(1,y) is also connected to (n,y)(n,y) and (x,1)(x,1) is also connected to (x,m)(x,m) for all 1≤x≤n,1≤y≤m1\le x\le n, 1\le y\le m.

Prof. Pang has three sons. We call them the first son, the second son and the third son. Each of them lives in a cell in Pangland. The ii-th son lives in cell (x_i,y_i)(x\_i, y\_i). No two sons live in the same cell. Prof. Pang wants to distribute the cells in Pangland to his sons such that

  • Each cell belongs to exactly one son.
  • There are cnt_icnt\_i cells that belong to the ii-th son for all 1≤i≤31\le i\le 3.
  • The cells that belong to the ii-th son are connected for all 1≤i≤31\le i\le 3.
  • The cell that the ii-th son lives in must belong to the ii-th son himself for all 1≤i≤31\le i\le 3.

Please help Prof. Pang to find a solution if possible.

입력

The first line contains a single integer TT (1≤T≤1051\leq T\leq 10^5) denoting the number of test cases.

For each test case, the first line contains two integers n,mn, m (3≤n,m≤5003\leq n,m \leq 500) separated by a single space.

The next line contains three positive integers cnt_1,cnt_2,cnt_3cnt\_1,cnt\_2,cnt\_3 (cnt_1+cnt_2+cnt_3=nmcnt\_1+cnt\_2+cnt\_3 = n m) separated by single spaces.

The ii-th line of the next 33 lines contains two integers x_i,y_ix\_i, y\_i (1≤x_i≤n,1≤y_i≤m1\le x\_i\le n, 1\le y\_i\le m) separated by a single space.

It is guaranteed that (x_1,y_1)(x\_1,y\_1), (x_2,y_2)(x\_2, y\_2), (x_3,y_3)(x\_3, y\_3) are distinct.

It is guaranteed that the sum of nmnm over all test cases is no more than 10610^6.

출력

For each test case, if there is no solution, output "-1" in one line. Otherwise, output nn lines. Each line should contain mm characters. The jj-th character in the ii-th line should be 'A' if cell (i,j)(i, j) belongs to the first son, 'B' if cell (i,j)(i, j) belongs to the second son and 'C' if cell (i,j)(i, j) belongs to the third son. Cell (x_i,y_i)(x\_i, y\_i) must belong to the ii-th son for all 1≤i≤31\le i\le 3. The cells that belong to the ii-th son must be connected for all 1≤i≤31\le i\le 3.

예제1

  1. 예제 1

    입력
    2
    3 3
    1 3 5
    1 1
    2 2
    3 3
    4 4
    5 5 6
    2 2
    2 3
    3 3
    
    예상 출력
    ABB
    CBC
    CCC
    BABB
    BABC
    CACC
    AACC