{"trustable":false,"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\"\u003e\r\n\t\u0026nbsp;\u003c/div\u003e\r\n\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tBeing bored John tried to watch \u003cspan data-scayt_word\u003d\"T.V\" data-scaytid\u003d\"1\"\u003eT.V\u003c/span\u003e. But, nothing to see . So John planned to play with blocks .\u0026nbsp;He has N blocks (1 \u0026lt;\u003d N \u0026lt;\u003d 30001) numbered\u003c/div\u003e\r\n\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tfrom 0 to N-1 . \u0026nbsp;Initially, there are N piles, and each pile must contain only one block. Then,, John do some operations P times (1 \u0026lt;\u003d P \u0026lt;\u003d 1000000). There are two kinds of operation:\u003c/div\u003e\r\n\u003cdiv class\u003d\"panel_content\"\u003e\r\n\t\u0026nbsp;\u003c/div\u003e\r\n\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tM X Y : Put the whole pile containing block X up to the pile containing Y. If X and Y are in the same pile, just ignore this command.\u003c/div\u003e\r\n\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tC X : Count the number of blocks under block X\u003cbr /\u003e\r\n\t\u003cbr /\u003e\r\n\tYou are request to find out the output for each C operation.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tThe first line contains integer P. Then P lines follow, each of which contain an operation describe above.\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tOutput the count for each C operations in one line.\u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\t\u003cpre\u003e\r\n\t\u003c/pre\u003e\r\n\t\u003cdiv style\u003d\"font-family:Courier New,Courier,monospace;\"\u003e\r\n\t\t\u003cpre\u003e\r\n\t\t6\r\nM 1 6\r\nC 1\r\nM 2 4\r\nM 2 6\r\nC 3\r\nC 4\u003c/pre\u003e\r\n\t\u003c/div\u003e\r\n\u003c/div\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\t\u003cpre\u003e\r\n\t\u003c/pre\u003e\r\n\t\u003cdiv style\u003d\"font-family:Courier New,Courier,monospace;\"\u003e\r\n\t\t\u003cpre\u003e\r\n\t\t1\r\n0\r\n2\u003c/pre\u003e\r\n\t\u003c/div\u003e\r\n\u003c/div\u003e"}}]}