We consider a set consisting of
entities and the relations on
. For simplicity, these
entities are labeled from
to
.
The ranking on
is defined as an
-order permutation
(
).
The winning relation on is defined as an ordered pair
(
,
), representing that the entity
wins in the competition with the entity
.
We say that the ranking satisfies the winning relation
if and only if there exist
such that
and
.
Given the number of entities , and
winning relations, you are required to construct the minimal number of rankings such that each winning relation is satisfied by at least one ranking in the constructed rankings.
The first line contains two positive integers
(
,
), representing the number of entities, and the number of winning relations.
Each of the following
lines contains two positive integers
(
,
), representing a winning relation
.
The first line contains a positive integer
, representing the minimal number of rankings needed.
Each of the following
lines contains
integers
(
), representing the
-th ranking
.