{"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\u003eAfter the dress rehearsal of CCPC Harbin Site 2019, $$$m$$$ contestants are still in the contest arena. They are taking photos, discussing the problems, and exchanging gifts.\u003c/p\u003e\u003cp\u003eInitially, everyone has exactly one gift in their hand. Note that some contestants may have the same type of gifts. Specifically, the type of the gift in the $$$i$$$-th contestant\u0027s hand can be represented as a positive integer $$$g_i$$$. Two contestants $$$i$$$ and $$$j \\ (1\\le i,j \\le m)$$$ share the same type of gifts if and only if $$$g_i\u003dg_j$$$ holds.\u003c/p\u003e\u003cp\u003eThere can be many rounds of gift exchanging between these $$$m$$$ contestants. In each round, two contestants may exchange their gifts with each other. Note that a pair of contestants can exchange gifts multiple times if they like. In the end, there will still be exactly one gift in each contestant\u0027s hand.\u003c/p\u003e\u003cp\u003eLet\u0027s denote $$$h_i$$$ as the type of gift in the $$$i$$$-th contestant\u0027s hand in the end. If $$$g_i\\neq h_i$$$ holds, the $$$i$$$-th contestant will be happy, because they have a different type of gift, otherwise they will be unhappy. Your task is to write a program to help them exchange gifts such that the number of happy contestants is maximized. For example, if $$$g\u003d[3,3,2,1,3]$$$ and $$$h\u003d[1,2,3,3,3]$$$, there will be $$$4$$$ happy contestants.\u003c/p\u003e\u003cp\u003eSince $$$m$$$ can be extremely large, you will be given $$$n$$$ sequences $$$s_1,s_2,\\dots,s_n$$$, and the sequence $$$g$$$ is equal to $$$s_n$$$. The $$$i$$$-th $$$(1\\le i \\le n)$$$ sequence will be given in one of the following two formats:\u003c/p\u003e\u003cul\u003e \u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e1 k q[1..k]\u003c/span\u003e\" ($$$1\\leq k\\leq 10^6$$$, $$$1\\leq q_i\\leq 10^9$$$): It means $$$s_i\u003d[q_1,q_2,\\dots,q_k]$$$. \u003c/li\u003e\u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e2 x y\u003c/span\u003e\" ($$$1\\leq x,y\\leq i-1$$$): It means $$$s_i\u003ds_x+s_y$$$. Here \"$$$+$$$\" denotes concatenation of sequences, for example $$$[3,3,2]+[2,2,3,3]\u003d[3,3,2,2,2,3,3]$$$. \u003c/li\u003e\u003c/ul\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe input contains multiple cases. The first line of the input contains a single integer $$$T$$$ ($$$1 \\leq T \\leq 10\\,000$$$), the number of cases.\u003c/p\u003e\u003cp\u003eFor each case, the first line of the input contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^6$$$), denoting the number of sequences. Each of the next $$$n$$$ lines describes a sequence in one of the two formats defined in the problem statement, where the $$$i$$$-th ($$$1\\le i \\le n$$$) line describes the sequence $$$s_i$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of all $$$n$$$ over all cases does not exceed $$$10^6$$$, and the sum of $$$k$$$ over all cases does not exceed $$$10^6$$$. It is also guaranteed that no sequence has a length that exceeds $$$10^{18}$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each case, print a single line containing a single integer denoting the maximum number of happy contestants.\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\u003e2\n1\n1 5 3 3 2 1 3\n3\n1 3 3 3 2\n1 4 2 2 3 3\n2 1 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n6\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}