Linker

Time limit1sMemory limit128 MB

Problem

Computer programs are usually built from several modules, and compiling such a program is normally done in two stages.

First, each source module is compiled independently into an object module. An object module has three parts:

  • the compiled program code,
  • an export table,
  • an import table.

The export table lists the symbols (for example, variable or function names) that this module defines and that other modules are allowed to use. The import table lists the external symbols that this module depends on.

After every module has been compiled, a program called the linker combines them into a single executable.

Every program has an entry point: the place where execution begins. The entry point is a symbol, and the module that "contains" it is the module that exports that symbol. To make the executable smaller, the linker keeps only the module that contains the entry point together with every module it depends on, directly or transitively; all other modules are called redundant.

Dependencies are expressed through symbols: a module depends on another module when it imports a symbol that the other module exports. If a symbol is exported by several modules, then a module importing that symbol depends on all of them.

Given the description of every module, report:

  • all non-redundant modules,
  • all duplicate exports: symbols that are exported by two or more modules and are imported by at least one non-redundant module,
  • all unresolved imports: symbols that are imported by at least one non-redundant module but are not exported by any module.

If the entry-point symbol is not exported by any module, it is treated as an unresolved import as well; in that case no module contains the entry point, so there are no non-redundant modules.

Input

The first line contains the name of the entry point.

The second line contains the number of modules $N$ ($1 \le N \le 100$).

After that come $N$ blocks, one per module:

  • the first line of a block is the module's name;
  • the next line contains the number of exports $E$ ($0 \le E \le 100$), followed by $E$ lines, each with one distinct export symbol;
  • the next line contains the number of imports $I$ ($0 \le I \le 100$), followed by $I$ lines, each with one distinct import symbol.

Every name in this problem is a non-empty string of at most $30$ characters made up of latin letters and digits.

Output

Print the non-redundant modules, then the duplicate exports, then the unresolved imports. To make the answer unique, print each group in a fixed order:

  • First print $M_R$, the number of non-redundant modules, followed by $M_R$ lines with their names in the order the modules appear in the input.
  • Then print $M_E$, the number of duplicate export symbols, followed by $M_E$ lines with those symbols in ascending ASCII order.
  • Then print $M_I$, the number of unresolved import symbols, followed by $M_I$ lines with those symbols in ascending ASCII order.

In ASCII order, digits come before uppercase letters, which come before lowercase letters.