{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eA common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e and \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e, each stack containing \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips. Each stack may contain chips of several different colors.\u003c/p\u003e\u003cp\u003eThe actual shuffle operation is performed by interleaving a chip from \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e with a chip from \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e as shown below for \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e \u003d 5:\u003c/p\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/389bf36422a0aaefc070870a6b91ed01?v\u003d1715822852\"\u003e\u003c/center\u003e\u003cp\u003eThe single resultant stack, \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e, contains 2 * \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips. The bottommost chip of \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e is the bottommost chip from \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e. On top of that chip, is the bottommost chip from \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e. The interleaving process continues taking the 2\u003csup\u003end\u003c/sup\u003e chip from the bottom of \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e and placing that on \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e, followed by the 2\u003csup\u003end\u003c/sup\u003e chip from the bottom of \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e and so on until the topmost chip from \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e is placed on top of \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eAfter the shuffle operation, \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e is split into 2 new stacks by taking the bottommost \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips from \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e to form a new \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e and the topmost \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips from \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e to form a new \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e. The shuffle operation may then be repeated to form a new \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eFor this problem, you will write a program to determine if a particular resultant stack \u003cb\u003eS\u003csub\u003e12\u003c/sub\u003e\u003c/b\u003e can be formed by shuffling two stacks some number of times.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cspan lang\u003d\"en-us\"\u003e\u003cp\u003eThe first line of input contains a single integer \u003ci\u003e\u003cb\u003eN\u003c/b\u003e\u003c/i\u003e, (1 ≤ \u003ci\u003e\u003cb\u003eN\u003c/b\u003e\u003c/i\u003e ≤ 1000) which is the number of datasets that follow.\u003c/p\u003e\u003cp\u003eEach dataset consists of four lines of input. The first line of a dataset specifies an integer \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e, (1 ≤ \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e ≤ 100) which is the number of chips in each initial stack (\u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e and \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e). The second line of each dataset specifies the colors of each of the \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips in stack \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e, starting with the bottommost chip. The third line of each dataset specifies the colors of each of the \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e chips in stack \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e starting with the bottommost chip. Colors are expressed as a single uppercase letter (\u003cb\u003eA\u003c/b\u003e through \u003cb\u003eH\u003c/b\u003e). There are no blanks or separators between the chip colors. The fourth line of each dataset contains 2 * \u003ci\u003e\u003cb\u003eC\u003c/b\u003e\u003c/i\u003e uppercase letters (\u003cb\u003eA\u003c/b\u003e through \u003cb\u003eH\u003c/b\u003e), representing the colors of the desired result of the shuffling of \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e\u003c/b\u003e and \u003cb\u003eS\u003csub\u003e2\u003c/sub\u003e\u003c/b\u003e zero or more times. The bottommost chip’s color is specified first.\u003c/p\u003e\u003c/span\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cspan lang\u003d\"en-us\"\u003e\u003cp\u003eOutput for each dataset consists of a single line that displays the dataset number (1 though \u003ci\u003e\u003cb\u003eN\u003c/b\u003e\u003c/i\u003e), a space, and an integer value which is the minimum number of shuffle operations required to get the desired resultant stack. If the desired result can not be reached using the input for the dataset, display the value negative 1 (\u003cb\u003e−1\u003c/b\u003e) for the number of shuffle operations.\u003c/p\u003e\u003c/span\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n4\r\nAHAH\r\nHAHA\r\nHHAAAAHH\r\n3\r\nCDE\r\nCDE\r\nEEDDCC\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1 2\r\n2 -1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}