{"problem":{"name":"A. Crystals","description":{"content":"Magicians at our University want to be alchemists. They work with crystals - they can mix some set of crystals and get another set of crystals. Of course, it is needed that these changes comply with t","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10049A"},"statements":[{"statement_type":"Markdown","content":"Magicians at our University want to be alchemists. They work with crystals - they can mix some set of crystals and get another set of crystals. Of course, it is needed that these changes comply with the rules because to change the set of crystals would be impossible otherwise even for magicians!\n\nAs in real life, a lot of work is needed to do to change sets of crystals. Therefore, each rule has a fixed amount of work it requires to apply.\n\nMagicians buy potato chips and find some magical crystals in the packages. There can't exist more than one crystal of the same type, because the stronger crystal of the same type consumes the weaker and, finally, the one crystal is left.\n\nThere is a special set of crystals called \"the dream set\". When magician owns all crystals of the dream set and nothing more, he is very proud of that (equally to a kid who collects all puponauts).\n\nYou are given the set magician owns initially, the dream set and the rules. You need to answer whether it is possible to get only the dream set and to print the minimal needed amount of work to get it. They will decide themselves if it is worth doing.\n\nNotes: \n\nFor example, if he owns crystals {1, 2, 3} and the rule is that we can change {2, 3} to {3, 4}, the magician can get {1, 3, 4} if he wants. But that would not satisfy him if the dream set was {1, 4}.\n\nThe first line contains the number of test cases T (1 ≤ T ≤ 50). \n\nIn the first line of every test case there are two integers n (1 ≤ n ≤ 12) and m (1 ≤ m ≤ 1000) - the number of different types of crystals and the number of rules.\n\nThe set of crystals is described with the number of its elements size (1 ≤ size ≤ n) and then size number of distinct integers, which shows the types of crystals belonging to the set (0 ≤ type ≤ n - 1). All numbers are separated by spaces.\n\nIn the second line of every test case there is an initial set of crystals owned by a magician.\n\nIn the the third line there is the dream set.\n\nIn the following m lines the rules are described as “_work S1 S2_” - (1 ≤ work ≤ 109), S1 and S2 are the sets of crystals. The integer amount of work is needed to be done to change the set S1 to the set S2.\n\nFor each test case output one line containing “_Case #tc: YES work_” or “_Case #tc: NO_” where tc is the number of the test case (starting from 1), “_YES_” or “_NO_” shows whether is it possible to get the dream set of crystals and work is the minimal amount of work which is needed to be done to get this set.\n\n## Input\n\nThe first line contains the number of test cases T (1 ≤ T ≤ 50). In the first line of every test case there are two integers n (1 ≤ n ≤ 12) and m (1 ≤ m ≤ 1000) - the number of different types of crystals and the number of rules.The set of crystals is described with the number of its elements size (1 ≤ size ≤ n) and then size number of distinct integers, which shows the types of crystals belonging to the set (0 ≤ type ≤ n - 1). All numbers are separated by spaces.In the second line of every test case there is an initial set of crystals owned by a magician.In the the third line there is the dream set.In the following m lines the rules are described as “_work S1 S2_” - (1 ≤ work ≤ 109), S1 and S2 are the sets of crystals. The integer amount of work is needed to be done to change the set S1 to the set S2.\n\n## Output\n\nFor each test case output one line containing “_Case #tc: YES work_” or “_Case #tc: NO_” where tc is the number of the test case (starting from 1), “_YES_” or “_NO_” shows whether is it possible to get the dream set of crystals and work is the minimal amount of work which is needed to be done to get this set.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $, let $ k \\in \\mathbb{Z}^+ $ be the input parameter.  \nA positive integer $ n $ is a *cool number* if it satisfies [undefined condition].\n\n**Constraints**  \n1. $ 1 \\leq T \\leq 10 $  \n2. For each test case, $ k \\in \\mathbb{Z}^+ $ (value unspecified)\n\n**Objective**  \nFor each test case $ k $, output all cool numbers $ n \\in \\mathbb{Z}^+ $ (in increasing order, space-separated), or $-1$ if none exist.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10049A","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}