Horses

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Big Horse is the God of Horses. He has nn different kinds of horses. Since his eyes are not so good, he cannot distinguish between the horses of the same kind.

Now he wants to arrange mm horses in a queue. But the horses are so active that they may change their positions at will. However, Big Horse noticed that only two adjacent horses may swap, and this may happen only if the two kinds of horses are friends. Since the horses can swap their positions at any time, Big Horse considers two queues equivalent if and only if one can be reached from the other one by a finite number of swaps.

Now Big Horse has a queue a=(a_1,,a_m)a = (a\_1, \ldots, a\_m) of horses. He wants to add some other horses to the left of the queue. However, Big Horse cannot tell left from right. So he wants to add a queue b=(b_1,,b_k)b = (b\_1, \ldots, b\_k) such that bb commutes with aa: in other words, b_1,,b_k,a_1,,a_mb\_1, \ldots, b\_k, a\_1, \ldots, a\_m is equivalent to a_1,,a_m,b_1,,b_ka\_1, \ldots, a\_m, b\_1, \ldots, b\_k.

However, the number of such bb may be too large. Big Horse only cares about the "minimal" such queues bb. Specifically, he is interested in bb such that:

  • bb commutes with aa,
  • bb is not equivalent to c_1,,c_k,d_1,,d_k"c\_1, \ldots, c\_{k'}, d\_1, \ldots, d\_{k"} such that cc commutes with aa and dd commutes with aa,
  • bb is lexicographically the least among all queues equivalent to it.

He found out that there are at most nn minimal queues. He asks you to help him find them.

입력

In the first line, there is an integer nn (1n200 1 \le n \le 200).

Then follow n1n - 1 lines. In the ii-th of these lines, there are nin - i integers. The jj-th integer in the ii-th of these lines is 11 if a horse of kind ii can swap with a horse of kind i+ji + j, and 00 otherwise.

The next line contains an integer mm (1m300,0001 \le m \le 300\\,000).

The last line contains mm integers a_1,,a_ma\_1, \ldots, a\_m: the kinds of horses in the queue (1a_in1 \le a\_i \le n).

출력

Output the minimal queues, one per line. Since a queue may be too long, when the minimal queue is bb, you only need to print the hash value b_1+b_2(n+1)++b_k(n+1)(k1)b\_1 + b\_2 \cdot (n + 1) + \ldots + b\_k \cdot (n + 1)^{(k - 1)} modulo 998,244,353998\\,244\\,353.

You should output the minimal queues in lexicographical order (order them before hashing).

힌트

The two minimal queues in the example are (1)(1) and (2,3)(2, 3).