{"trustable":true,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eLittle Bob studied Trie in Data Structure class. He learned that Trie is a rooted tree to store some strings. There is a character on each edge of a Trie. (In this problem, the valid characters are lowercase Latin letters.)\u003cbr\u003e\u003cbr\u003eBob draws a Trie with n nodes, and the nodes are numbered with integers from 1 to n. The number of the root node is always 1.\u003cbr\u003e\u003cbr\u003eHe uses S\u003csub\u003ei\u003c/sub\u003e to denote the string concatenated with characters on the path from the root to node i. It can be seen that S1 is the empty string. Furthermore, for a set P \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/6236457540535f4b8d430e155138d9a4?v\u003d1724989571\"\u003e {1, 2, . . . , n}, S\u003csub\u003eP\u003c/sub\u003e \u003d {S\u003csub\u003ei\u003c/sub\u003e | i \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ce999a0d934cb3851fdce0952f8b594e?v\u003d1724989571\"\u003e P}.\u003cbr\u003e\u003cbr\u003eBob defines a kind of trait on this Trie. The trait can be described with a set P \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/6236457540535f4b8d430e155138d9a4?v\u003d1724989571\"\u003e {1, 2, . . . , n}. We say a string a has this trait, if and only if there exists a string b \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ce999a0d934cb3851fdce0952f8b594e?v\u003d1724989571\"\u003e S\u003csub\u003eP\u003c/sub\u003e such that a ends with b. Here string a ends with string b means the last |b| characters of a is exactly b. (Note that every string ends with the empty string).\u003cbr\u003e\u003cbr\u003eBob also defines a mapping f on P \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/6236457540535f4b8d430e155138d9a4?v\u003d1724989571\"\u003e{1, 2, ..., n}, and f (P) is also a subset of {1, 2, . . . , n}. i \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ce999a0d934cb3851fdce0952f8b594e?v\u003d1724989571\"\u003e f (P) if and only if there exists j \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ce999a0d934cb3851fdce0952f8b594e?v\u003d1724989571\"\u003e P such that S\u003csub\u003ej\u003c/sub\u003e ends with S\u003csub\u003ei\u003c/sub\u003e.\u003cbr\u003e\u003cbr\u003eInitially, there is no traits been defined. Bob will add traits whenever he wants. Let D\u003csub\u003ei\u003c/sub\u003e denote the number of traits that S\u003csub\u003ei\u003c/sub\u003e has until now. Note that D\u003csub\u003ei\u003c/sub\u003e may change when a new trait is added.\u003cbr\u003e\u003cbr\u003eBesides adding new traits, Bob may also ask you something about his Trie. In each query, Bob will give you a set P \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/6236457540535f4b8d430e155138d9a4?v\u003d1724989571\"\u003e {1, 2, . . . , n}, and you need to compute \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/626495563529e7bbfaeda2e55ae40a36?v\u003d1724989571\"\u003e. Are you willing to do this for Bob?\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains an integer T (T ≤ 5), denoting the number of the test cases.\u003cbr\u003e\u003cbr\u003eFor each test case, the first line contains an integer n(1 ≤ n ≤ 10\u003csup\u003e5\u003c/sup\u003e).\u003cbr\u003e\u003cbr\u003eFrom the second to the n-th line, this n - 1 lines describe Bob\u0027 s Trie. The i-th line contains an integer u(u \u0026lt; i), and a lowercase letter c, which means that the father of node i is node u and the character on that edge is c. We ensure that for each node i, letters on edges connecting i and its children are all different.\u003cbr\u003e\u003cbr\u003eThe next line contains an integer m(m ≤ 10\u003csup\u003e5\u003c/sup\u003e), which means there are m operations.\u003cbr\u003e\u003cbr\u003eThe next m lines describe all operations. In each line, the first integer indicates the type of this operation. 1 means Bob will add a new trait and 2 means Bob is asking you a question. The second integer k is the size of set P , and the next k integers are the elements of P. We ensure that these k integers are different, and they are all between 1 and n. The total size of the m sets will not be larger than 5·10\u003csup\u003e5\u003c/sup\u003e."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output the answer for each query operation, one answer in a line."}},{"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\u003e1\r\n6\r\n1 a\r\n1 b\r\n1 c\r\n3 a\r\n3 b\r\n5\r\n1 2 3 4\r\n2 2 5 6\r\n1 2 2 3\r\n2 2 4 5\r\n2 1 6\t\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3\r\n4\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}