{"raw_statement":[{"iden":"statement","content":"You are given n magical numbers a1, a2, ..., an, such that the length of each of these numbers is 20 digits.\n\nYou can move from the ith number to the jth number, if the number of common digits between ai and aj is *exactly* 17 digits.\n\nThe number of common digits between two numbers x and y is computed is follow:\n\nWhere countXi is the frequency of the ith digit in the number x, and countYi is the frequency of the ith digit in the number y.\n\nYou are given two integers s and e, your task is to find the minimum numbers of moves you need to do, in order to finish at number ae starting from number as.\n\nThe first line contains an integer T (1 ≤ T ≤ 250), where T is the number of test cases.\n\nThe first line of each test case contains three integers n, s, and e (1 ≤ n ≤ 250) (1 ≤ s, e ≤ n), where n is the number of magical numbers, s is the index of the number to start from it, and e is the index of the number to finish at it.\n\nThen n lines follow, giving the magical numbers. All numbers consisting of digits, and with length of 20 digits. Leading zeros are allowed.\n\nFor each test case, print a single line containing the minimum numbers of moves you need to do, in order to finish at number ae starting from number as. If there is no answer, print -1.\n\nIn the first test case, you can move from a1 to a2, from a2 to a3, and from a3 to a5. So, the minimum number of moves is 3 moves.\n\n"},{"iden":"input","content":"The first line contains an integer T (1 ≤ T ≤ 250), where T is the number of test cases.The first line of each test case contains three integers n, s, and e (1 ≤ n ≤ 250) (1 ≤ s, e ≤ n), where n is the number of magical numbers, s is the index of the number to start from it, and e is the index of the number to finish at it.Then n lines follow, giving the magical numbers. All numbers consisting of digits, and with length of 20 digits. Leading zeros are allowed."},{"iden":"output","content":"For each test case, print a single line containing the minimum numbers of moves you need to do, in order to finish at number ae starting from number as. If there is no answer, print -1."},{"iden":"note","content":"In the first test case, you can move from a1 to a2, from a2 to a3, and from a3 to a5. So, the minimum number of moves is 3 moves."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case:  \n- Let $ n \\in \\mathbb{Z} $ be the number of magical numbers.  \n- Let $ s, e \\in \\{1, \\dots, n\\} $ be the start and end indices.  \n- Let $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of strings, each of length 20, representing the magical numbers.  \n- For each $ a_i $, define its digit frequency vector $ f_i \\in \\mathbb{N}^{10} $, where $ f_i[d] $ is the count of digit $ d \\in \\{0,1,\\dots,9\\} $ in $ a_i $.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 250 $  \n2. For each test case:  \n   - $ 1 \\le n \\le 250 $  \n   - $ 1 \\le s, e \\le n $  \n   - Each $ a_i $ is a string of exactly 20 decimal digits (leading zeros allowed).  \n\n**Edge Condition**  \nThere is a directed edge from node $ i $ to node $ j $ ($ i \\ne j $) if and only if:  \n$$\n\\sum_{d=0}^{9} \\min(f_i[d], f_j[d]) = 17\n$$\n\n**Objective**  \nFind the minimum number of moves (i.e., shortest path in terms of edges) from node $ s $ to node $ e $ in the directed graph defined above.  \nIf no such path exists, output $-1$.","simple_statement":"You are given n magical 20-digit numbers.  \nYou can move from number i to number j if they share exactly 17 same digits (counting digit frequencies).  \nFind the minimum number of moves to go from number s to number e.  \nIf impossible, return -1.","has_page_source":false}