SP1797 CARD - Cardsharper
Description
Zenek is a well known (at least in Byteotia) card-sharper. He spent most of his best years practicing one card shuffle with his deck of **n** cards, which for simplicity we will call 1, 2, ..., **n**. Unfortunately, it turns out that knowing this one card shuffle **a** is not enough to earn a good living. To become rich and famous Zenek needs to know **k** shuffles **c $ _{1} $** , ..., **c $ _{k} $** . As he doesn't have enough time to learn all of them, he decided to learn only one shuffle **b** so that using both **a** and **b** he will be able to perform as many of **c $ _{i} $** as it is possible.
Each shuffle is described by **n** numbers **t $ _{1} $** , **t $ _{2} $** , ..., **t $ _{n} $** . Such description means that after performing shuffle, card that was originally at position **i** will be at position **t $ _{i} $** .
### Task
Find shuffle **b** maximizing number of shuffles that can be performed.
Input Format
First line contains **n** (2 n n numbers **a $ _{1} $** , **a $ _{2} $** , ..., **a $ _{n} $** describing shuffle that Zenek already knows. Third line contains **k** (2 k i-th of the next **k** lines contains description of **c $ _{i} $** .
Output Format
First line contains description of the shuffle **b** that Zenek should learn. **i**-th of the next **k** lines contains:
- `-1` when it is not possible to perform **c $ _{i} $** using only **a** and **b**
- **m**, **r $ _{1} $** , **r $ _{2} $** , ..., **r $ _{m} $** (0 m r $ _{i} $ a **r $ _{1} $** times, then **b** **r $ _{2} $** times, then **a** **r $ _{3} $** times and so on is the same as applying shuffle **c $ _{i} $** once.