Chains Solitaire
시간 제한1초메모리 제한512 MB
52장의 카드를 7개 열로 나눠 받은 뒤, 같은 무늬 K부터 A까지 네 개의 열을 만드는 이동 순서를 찾거나 불가능을 판정한다.
문제
In this problem a variation of <<Scorpion>> solitaire is presented.
You are given a deck of playing cards which are dealt into seven columns. Every column may have an arbitrary number of the cards, including cases when there are no cards in some columns (we call such columns empty). Each card has a suit (, , , or ) and a rank (in increasing order: A, , , , , , , , , , J, Q, K).
On each turn you are allowed to do the following: you choose the current card in some column (you may pick any) and move it onto the bottom card of another column together with all cards on top of it (a bottom part of column is moved as one unit). You are allowed to move the current card only onto a card of the same suit and rank larger exactly by . For example, can be moved only onto , and A can be moved only onto as it is shown in picture below. If the current card has rank K, you are allowed to move it only onto an empty column (together with all cards on top of it as well) and only if it lies on an another card (not on the top of a column).

The goal of the game is to build columns of suit sequences from king to ace (K is in top of column, and A is in bottom).
입력
You are given lines, the -th of which describes the -th column. The -th line starts with integer --- the number of cards in the -th column (), followed by two-symbol strings which describe cards in the -th column from top to bottom. The first symbol encodes a rank ("A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q" and "K" for A, , , , , , , , , , J, Q and K correspondingly), the second one encodes a suit ("D", "H", "S" and "C" for , , and correspondingly).
It is guaranteed that the input data contains all cards and that every of them occurs exactly once.
출력
If it is impossible to win the game, print "NO". Otherwise, in the first line print "YES", in the second line print the number of moves, and in the third line print cards in order of making turns. If there are several solutions, output any of them.