Similar Cities

No attempts yetTime limit2sMemory limit128 MB

Problem

In SBP (the Super Rich Country) there are a great many cities. Every city contains houses, shops, and exactly one town hall. SBP is a very orderly country, so every city has a degree. A degree of kk means that exactly kk one-way roads leave every building, numbered 00 through k1k-1.

Paths that start at the town hall are especially important. Such a path is described by the sequence of road numbers taken along the way. For example, the path described by the sequence 103103 is walked like this:

  1. Start at the town hall. Take the road numbered 11, arriving at building XX.
  2. Take road number 00 from XX to building YY.
  3. Take road number 33 from YY to building ZZ.
  4. The path ends at building ZZ, which may be a house, a shop, or the town hall.

You are given the road layouts of two cities that share the same degree ss. Find the shortest sequence that, in one of the two cities, describes a path from the town hall to a house, while in the other city it describes a path from the town hall to a building that is not a house (a shop or the town hall). In other words, find the shortest sequence for which the two cities disagree on whether the walk ends at a house.

Each road number is a single digit from 00 to s1s-1 (note s10s \le 10), so a sequence is written as its road numbers joined together with no separators.

Input

The first line contains the number of test cases TT (1T201 \le T \le 20). Each test case is given as follows.

The first line of a test case has five integers n1n_1, d1d_1, n2n_2, d2d_2, ss (3n1,n210003 \le n_1, n_2 \le 1000, 0<d1n120 < d_1 \le n_1 - 2, 0<d2n220 < d_2 \le n_2 - 2, 1s101 \le s \le 10): the number of buildings in the first city, the number of houses in the first city, the number of buildings in the second city, the number of houses in the second city, and the degree shared by both cities.

In each city the town hall is building 00, the houses are buildings 11 through dd, and the shops are buildings d+1d+1 through n1n-1.

The next n1n_1 lines describe the first city: line ii (counting buildings from 00) contains ss integers in the range 00 to n11n_1 - 1, the destinations of roads 0,1,,s10, 1, \dots, s-1 leaving building ii. The following n2n_2 lines describe the second city in the same way. Several roads may connect the same pair of buildings, and a road may start and end at the same building.

Output

Print TT lines; the ii-th holds the answer for the ii-th test case. If no valid sequence exists, print a single 00. Otherwise print the length of the shortest valid sequence, then a single space, then the sequence itself. If several shortest sequences exist, print the lexicographically smallest one (the one that would come first in a dictionary).