{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are given $$$n$$$ patterns $$$p_1, p_2, \\dots, p_n$$$ and $$$m$$$ strings $$$s_1, s_2, \\dots, s_m$$$. Each pattern $$$p_i$$$ consists of $$$k$$$ characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. Each string $$$s_j$$$ consists of $$$k$$$ lowercase Latin letters.\u003c/p\u003e\u003cp\u003eA string $$$a$$$ matches a pattern $$$b$$$ if for each $$$i$$$ from $$$1$$$ to $$$k$$$ either $$$b_i$$$ is a wildcard character or $$$b_i\u003da_i$$$.\u003c/p\u003e\u003cp\u003eYou are asked to rearrange the patterns in such a way that the first pattern the $$$j$$$-th string matches is $$$p[mt_j]$$$. You are allowed to leave the order of the patterns unchanged.\u003c/p\u003e\u003cp\u003eCan you perform such a rearrangement? If you can, then print any valid order.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \\le n, m \\le 10^5$$$, $$$1 \\le k \\le 4$$$)\u0026nbsp;— the number of patterns, the number of strings and the length of each pattern and string.\u003c/p\u003e\u003cp\u003eEach of the next $$$n$$$ lines contains a pattern\u0026nbsp;— $$$k$$$ characters that are either lowercase Latin letters or underscores. All patterns are pairwise distinct.\u003c/p\u003e\u003cp\u003eEach of the next $$$m$$$ lines contains a string\u0026nbsp;— $$$k$$$ lowercase Latin letters, and an integer $$$mt$$$ ($$$1 \\le mt \\le n$$$)\u0026nbsp;— the index of the first pattern the corresponding string should match.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eNO\u003c/span\u003e\" if there is no way to rearrange the patterns in such a way that the first pattern that the $$$j$$$-th string matches is $$$p[mt_j]$$$.\u003c/p\u003e\u003cp\u003eOtherwise, print \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYES\u003c/span\u003e\" in the first line. The second line should contain $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$\u0026nbsp;— the order of the patterns. If there are multiple answers, print any of them.\u003c/p\u003e"}},{"title":"Examples","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\u003e5 3 4\n_b_d\n__b_\naaaa\nab__\n_bcd\nabcd 4\nabba 2\ndbcd 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\n3 2 4 5 1 \n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003e1 1 3\n__c\ncba 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eNO\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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 2 2\na_\n_b\nab 1\nab 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eNO\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eThe order of patterns after the rearrangement in the first example is the following: \u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eaaaa\u003c/span\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e__b_\u003c/span\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eab__\u003c/span\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e_bcd\u003c/span\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e_b_d\u003c/span\u003e \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThus, the first string matches patterns \u003cspan class\u003d\"tex-font-style-tt\"\u003eab__\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-tt\"\u003e_bcd\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-tt\"\u003e_b_d\u003c/span\u003e in that order, the first of them is \u003cspan class\u003d\"tex-font-style-tt\"\u003eab__\u003c/span\u003e, that is indeed $$$p[4]$$$. The second string matches \u003cspan class\u003d\"tex-font-style-tt\"\u003e__b_\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-tt\"\u003eab__\u003c/span\u003e, the first of them is \u003cspan class\u003d\"tex-font-style-tt\"\u003e__b_\u003c/span\u003e, that is $$$p[2]$$$. The last string matches \u003cspan class\u003d\"tex-font-style-tt\"\u003e_bcd\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-tt\"\u003e_b_d\u003c/span\u003e, the first of them is \u003cspan class\u003d\"tex-font-style-tt\"\u003e_bcd\u003c/span\u003e, that is $$$p[5]$$$.\u003c/p\u003e\u003cp\u003eThe answer to that test is not unique, other valid orders also exist.\u003c/p\u003e\u003cp\u003eIn the second example \u003cspan class\u003d\"tex-font-style-tt\"\u003ecba\u003c/span\u003e doesn\u0027t match \u003cspan class\u003d\"tex-font-style-tt\"\u003e__c\u003c/span\u003e, thus, no valid order exists.\u003c/p\u003e\u003cp\u003eIn the third example the order (\u003cspan class\u003d\"tex-font-style-tt\"\u003ea_\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-tt\"\u003e_b\u003c/span\u003e) makes both strings match pattern $$$1$$$ first and the order (\u003cspan class\u003d\"tex-font-style-tt\"\u003e_b\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-tt\"\u003ea_\u003c/span\u003e) makes both strings match pattern $$$2$$$ first. Thus, there is no order that produces the result $$$1$$$ and $$$2$$$.\u003c/p\u003e"}}]}