Connecting Two Islands

No attempts yetTime limit3sMemory limit128 MB

Problem

The long war in Byteland is over. The government decided to rebuild the transport network first.

Byteland consists of two islands. Before the war every two cities on the same island were joined directly by a single two-way track, and some of those tracks were destroyed during the war. At most 15 tracks were destroyed.

Until the war there was no way to travel between the two islands. Once the rebuilding is done, ferry routes running between the islands will be added so that every two cities in Byteland are joined directly by a track or by a ferry route. Two cities on different islands must be joined by a ferry route, and two cities on the same island must be joined by a track.

Everything in Byteland is written in binary. Train ticket prices and ferry ticket prices are 0 or 1 as well.

The government keeps the ticket price of every track that survived the war. The prices of the rebuilt tracks and of the new ferry routes have to follow one rule. For three distinct cities XX, YY, ZZ, write CC for the ticket price of the track or ferry route that joins two cities directly. Then

C(X,Y)+C(Y,Z)C(X,Z)C(X, Y) + C(Y, Z) \ge C(X, Z)

A direct trip is always at most as expensive as a trip through another city.

The track information of both islands is given. Decide whether the tracks and the ferry routes can be arranged so that the rule holds, and when they can, work out the final transport plan.

Input

The first line has the number of test cases TT. (1T1001 \le T \le 100)

Each test case has the following form.

  • The first line has the number of cities on the first island of Byteland, C1C_1. (1C11001 \le C_1 \le 100)
  • Each of the next C1C_1 lines has C1C_1 characters, each of them 0, 1 or x. If the jj-th character of the ii-th line is 0, the track between city ii and city jj of that island has ticket price 0. If it is 1, the ticket price is 1. If it is x, that track was destroyed during the war.
  • The next line has the number of cities on the second island, C2C_2. (1C21001 \le C_2 \le 100)
  • Each of the next C2C_2 lines has C2C_2 characters in the same format as the first island.

Every table given is symmetric about its diagonal, and the ii-th character of the ii-th line is always 0.

The two tables together contain at most 30 characters x. A table is symmetric, so each destroyed track shows up as two x characters.

Watch out: the tracks that survived the war may already break the rule.

Output

For each test case print YES on the first line when a transport plan that follows the rule can be built, and NO when it cannot.

After YES, print the final transport plan on C1+C2C_1 + C_2 lines of C1+C2C_1 + C_2 characters each. Cities on island 1 are numbered 1 to C1C_1, and cities on island 2 are numbered C1+1C_1 + 1 to C1+C2C_1 + C_2. The jj-th character of the ii-th line has to be the ticket price, 0 or 1, of the track or ferry route joining city ii and city jj, and the table has to be symmetric.

When several plans follow the rule, print only one of them. Concatenate the lines of the table from top to bottom into a string of length (C1+C2)2(C_1 + C_2)^2, and print the plan whose string comes first in lexicographic order.