Lady's Gift
On her birthday, Lady received a gift — a network. The network contains nodes, numbered with integers from to . Each node is assigned a specific letter, denoted as for the node with number .
There are one-way connections between some pairs of nodes. Each node has exactly one outgoing one-way connection. Let the connection for the node with number lead to the node with number . Note that can be equal to — in this case, it is considered that the connection from the node with number leads to the same node.
Let and . Thus, is the number of the node where a chip will end up if it is placed in the node with number and moved along the connection from the current node times.
Lady created a matrix of size , where . Thus, the -th row of the matrix is a sequence of letters, where the first letter equals , the second letter equals , the third equals , and so on.
Lady informed some rows of the matrix and asks you to construct any network that corresponds to the known rows of the matrix .
Input
The first line contains a single integer — the number of nodes in the network.
The next lines describe the matrix . Each of these lines contains lowercase Latin letters, representing the corresponding row of matrix , or a single symbol "?
" if Lady did not inform the corresponding row.
It is guaranteed that there exists at least one network that satisfies the given conditions.
Output
In the first line, output a string consisting of lowercase Latin letters — the letters written on the nodes of the network.
In the second line, output integers — the numbers of the nodes to which the connections from the corresponding nodes lead.
The matrix corresponding to this network must be exactly equal to the matrix in all rows that Lady informed.
If there are multiple correct answers, you are allowed to output any of them.
Examples
Note
In the first example, and , so . Since , all for are also equal to . Accordingly, the second letter of the first row equals , and the third equals .
Below are the images of networks from the examples. The numbers in the corners indicate the node numbers, the letters indicate the values written on the corresponding nodes, and the arrows indicate the one-way connections.
Network from the first example
Network from the second example
Scoring
Let be the number of rows that Lady did not inform.
We call a network a set of pairs and unit nodes if the network can be divided into nodes, from which the connection leads to itself (i.e., ), and pairs of nodes such that and .
We call a network a set of stars if the network can be divided into separate "stars", each of which consists of a main node , from which the connection leads to itself (i.e., ), and a set of secondary nodes such that for . Note that the stars in the network may have different sizes and consist only of one main node.
We call a network a tree with the root at node if from node the connection leads to itself (i.e., ), and for each other node it is possible to reach node using the network connections (i.e., for each there is such that ).
We call a network a cycle if starting from any node it is possible to reach any other node using the network connections (i.e., for all there is such that ).
( points): , ;
( points): , , for (the network is a set of pairs and unit nodes);
( points): , , for (the network is a set of stars);
( points): , , and for (the network is a tree with the root at node );
( points): , , for all there is such that (the network is a cycle);
( points): , ;
( points): ;
( points): , ;
( points): without additional restrictions.