{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\r\n\t\u003cspan style\u003d\"float:right\"\u003e\u003ca href\u003d\"http://uva.onlinejudge.org/external/102/10205.pdf\" target\u003d\"_blank\"\u003e\u003cimg alt\u003d\"Download as PDF\" border\u003d\"0\" height\u003d\"26\" src\u003d\"http://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png\" title\u003d\"Download as PDF\" width\u003d\"100\" /\u003e\u003c/a\u003e\u003c/span\u003e\u003c/p\u003e\r\n\u003ch2 style\u003d\"margin-bottom: 0px; color: rgb(0, 0, 0); text-align: right;\"\u003e\r\n\t\u0026nbsp;\u003c/h2\u003e\r\n\u003ch2 style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tProblem E: Stack \u0026#39;em Up\u003c/h2\u003e\r\n\u003ch2 style\u003d\"margin-bottom: 0px; color: rgb(0, 0, 0); text-align: right;\"\u003e\r\n\t\u003cimg src\u003d\"http://uva.onlinejudge.org/external/102/p10205.gif\" style\u003d\"color: rgb(34, 34, 34);\" /\u003e\u003c/h2\u003e\r\n\u003cp\u003e\r\n\t\u003cspan style\u003d\"color: rgb(0, 0, 0);\"\u003eA standard playing card deck contains 52 cards, 13 values in each of four suits. The values are named\u0026nbsp;\u003c/span\u003e\u003ci style\u003d\"color: rgb(0, 0, 0);\"\u003e2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.\u003c/i\u003e\u003cspan style\u003d\"color: rgb(0, 0, 0);\"\u003e\u0026nbsp;The suits are named\u0026nbsp;\u003c/span\u003e\u003ci style\u003d\"color: rgb(0, 0, 0);\"\u003eClubs, Diamonds, Hearts, Spades\u003c/i\u003e\u003cspan style\u003d\"color: rgb(0, 0, 0);\"\u003e. A particular card in the deck can be uniquely identified by its value and suit, typically denoted\u0026nbsp;\u003c/span\u003e\u003ci style\u003d\"color: rgb(0, 0, 0);\"\u003e\u0026lt;value\u0026gt;\u003c/i\u003e\u003cspan style\u003d\"color: rgb(0, 0, 0);\"\u003e\u0026nbsp;of\u0026nbsp;\u003c/span\u003e\u003ci style\u003d\"color: rgb(0, 0, 0);\"\u003e\u0026lt;suit\u0026gt;\u003c/i\u003e\u003cspan style\u003d\"color: rgb(0, 0, 0);\"\u003e. For example, \u0026quot;9 of Hearts\u0026quot; or \u0026quot;King of Spades\u0026quot;. Traditionally a new deck is ordered first alphabetically by suit, then by value in the order given above.\u003c/span\u003e\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tThe Big City has many Casinos. In one such casino the dealer is a bit crooked. She has perfected several shuffles; each shuffle rearranges the cards in exactly the same way whenever it is used. A very simple example is the \u0026quot;bottom card\u0026quot; shuffle which removes the bottom card and places it at the top. By using various combinations of these known shuffles, the crooked dealer can arrange to stack the cards in just about any particular order.\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tYou have been retained by the security manager to track this dealer. You are given a list of all the shuffles performed by the dealer, along with visual cues that allow you to determine which shuffle she uses at any particular time. Your job is to predict the order of the cards after a sequence of shuffles.\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\t\u0026nbsp;\u003c/p\u003e\r\n\u003ch3 style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tInput\u003c/h3\u003e\r\n\u003cp\u003e\r\n\t\u003cb style\u003d\"color: rgb(0, 0, 0);\"\u003eThe input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.\u003c/b\u003e\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tInput consists of an integer\u0026nbsp;\u003ci\u003en\u003c/i\u003e\u0026nbsp;\u0026lt;\u003d 100, the number of shuffles that the dealer knows. \u003cspan data-scayt_word\u003d\"52n\" data-scaytid\u003d\"1\"\u003e52\u003ci\u003en\u003c/i\u003e\u003c/span\u003e\u0026nbsp;integers follow. Each consecutive 52 integers will comprise all the integers from 1 to 52 in some order. Within each set of 52 integers,\u0026nbsp;\u003ci\u003ei\u003c/i\u003e\u0026nbsp;in position\u0026nbsp;\u003ci\u003ej\u003c/i\u003e\u0026nbsp;means that the shuffle moves the\u0026nbsp;\u003ci\u003e\u003cspan data-scayt_word\u003d\"ith\" data-scaytid\u003d\"2\"\u003ei\u003csup\u003eth\u003c/sup\u003e\u003c/span\u003e\u003c/i\u003e\u0026nbsp;card in the deck to position\u0026nbsp;\u003ci\u003ej\u003c/i\u003e.\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tSeveral lines follow; each containing an integer\u0026nbsp;\u003ci\u003ek\u003c/i\u003e\u0026nbsp;between 1 and\u0026nbsp;\u003ci\u003en\u003c/i\u003e\u0026nbsp;indicating that you have observed the dealer applying the\u0026nbsp;\u003ci\u003e\u003cspan data-scayt_word\u003d\"kth\" data-scaytid\u003d\"3\"\u003ek\u003csup\u003eth\u003c/sup\u003e\u003c/span\u003e\u003c/i\u003e\u0026nbsp;shuffle given in the input.\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\t\u0026nbsp;\u003c/p\u003e\r\n\u003ch3 style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tOutput\u003c/h3\u003e\r\n\u003cp\u003e\r\n\t\u003cb style\u003d\"color: rgb(0, 0, 0);\"\u003eFor each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.\u003c/b\u003e\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tAssume the dealer starts with a new deck ordered as described above. After all the shuffles had been performed, give the names of the cards in the deck, in the new order.\u003c/p\u003e\r\n\u003cp style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\t\u0026nbsp;\u003c/p\u003e\r\n\u003ch3 style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tSample Input\u003c/h3\u003e\r\n\u003cpre style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n1\r\n\r\n2\r\n2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\r\n27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 51\r\n52 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\r\n27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1\r\n1\r\n2\u003c/pre\u003e\r\n\u003ch3 style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\n\tOutput for Sample Input\u003c/h3\u003e\r\n\u003cpre style\u003d\"color: rgb(0, 0, 0);\"\u003e\r\nKing of Spades\r\n2 of Clubs\r\n4 of Clubs\r\n5 of Clubs\r\n6 of Clubs\r\n7 of Clubs\r\n8 of Clubs\r\n9 of Clubs\r\n10 of Clubs\r\nJack of Clubs\r\nQueen of Clubs\r\nKing of Clubs\r\nAce of Clubs\r\n2 of Diamonds\r\n3 of Diamonds\r\n4 of Diamonds\r\n5 of Diamonds\r\n6 of Diamonds\r\n7 of Diamonds\r\n8 of Diamonds\r\n9 of Diamonds\r\n10 of Diamonds\r\nJack of Diamonds\r\nQueen of Diamonds\r\nKing of Diamonds\r\nAce of Diamonds\r\n2 of Hearts\r\n3 of Hearts\r\n4 of Hearts\r\n5 of Hearts\r\n6 of Hearts\r\n7 of Hearts\r\n8 of Hearts\r\n9 of Hearts\r\n10 of Hearts\r\nJack of Hearts\r\nQueen of Hearts\r\nKing of Hearts\r\nAce of Hearts\r\n2 of Spades\r\n3 of Spades\r\n4 of Spades\r\n5 of Spades\r\n6 of Spades\r\n7 of Spades\r\n8 of Spades\r\n9 of Spades\r\n10 of Spades\r\nJack of Spades\r\nQueen of Spades\r\nAce of Spades\r\n3 of Clubs\u003c/pre\u003e"}}]}