{"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\u003eLewis likes playing chess. Now he has $$$n$$$ rooks on the chessboard with $$$n$$$ rows and $$$n$$$ columns. All rows of the chessboard are labelled with $$$1$$$ through $$$n$$$ from top to bottom. All columns of the chessboard are labelled with $$$1$$$ through $$$n$$$ from left to right. All rooks are labelled with $$$1$$$ through $$$n$$$ as well. At the very beginning, \u003cspan class\u003d\"tex-font-style-bf\"\u003eeach row or column contains exactly one rook\u003c/span\u003e. However, Lewis allows a square with two or more rooks during the game. \u003c/p\u003e\u003cp\u003eNow he starts to play a game named Supreme Command. He will provide several supreme commands to all rooks. All possible commands are in the following four different formats.\u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eL k\u003c/span\u003e: Every rook moves $$$k$$$ squares to the left; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eR k\u003c/span\u003e: Every rook moves $$$k$$$ squares to the right; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eU k\u003c/span\u003e: Every rook moves $$$k$$$ squares upward; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eD k\u003c/span\u003e: Every rook moves $$$k$$$ squares downward. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor a Supreme Command with given number $$$k$$$, if a rook, after moving less than $$$k$$$ squares, had arrived at a boundary (which locates in the left-most columns, right-most column, top row or bottom row) such that the rook cannot move further, it would stay there and not move outside the chessboard.\u003c/p\u003e\u003cp\u003eHe will also have several queries about rooks. The only two possible formats about queries are listed as follows.\u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e? k\u003c/span\u003e: Ask the current position of the $$$k$$$-th rook; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e!\u003c/span\u003e: Ask how many pairs of rooks there are currently located in the same square. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour task in this problem is to answer these queries correctly.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe input contains several test cases, and the first line contains a positive integer $$$T$$$ indicating the number of test cases which is up to $$$1000$$$.\u003c/p\u003e\u003cp\u003eFor each test case, the first line contains two integers $$$n$$$ which is described as above, and $$$m$$$ indicating the total number of supreme commands and queries, where $$$1 \\leq n, m \\leq 3 \\times 10^5$$$.\u003c/p\u003e\u003cp\u003eEach of the following $$$n$$$ lines contains two integers $$$x$$$ and $$$y$$$, describing a rook located at the intersection of the $$$x$$$-th row and the $$$y$$$-th column, where $$$1 \\leq x, y \\leq n$$$.\u003c/p\u003e\u003cp\u003eThen the following $$$m$$$ lines describe all Supreme Commands and queries in chronological order, where all given parameters $$$k$$$ are integers ranged from $$$1$$$ to $$$n$$$.\u003c/p\u003e\u003cp\u003eWe guarantee that the sum of $$$n$$$ and the sum of $$$m$$$ in all test cases are up to $$$10^6$$$ respectively.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, output several lines to answer all queries.\u003c/p\u003e\u003cp\u003eFor each query of the first type (\"? $$$k$$$\"), output a line containing two integers $$$x$$$ and $$$y$$$, which indicate the current position of the $$$k$$$-th rook is the intersection of the $$$x$$$-th row and the $$$y$$$-th column. You should output exactly one whitespace between these two numbers.\u003c/p\u003e\u003cp\u003eFor each query of the second type (\"!\"), output a line containing an integer which indicates the number of pairs of rocks that are currently located in the same square.\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\u003e1\n4 9\n3 4\n2 1\n4 2\n1 3\nL 2\n? 1\n? 2\nR 1\n? 1\n? 3\n!\nU 3\n!\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3 2\n2 1\n3 3\n4 2\n0\n3\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 following figures illustrate the chessboard at the beginning and after each Supreme Commands in the sample case.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/90daaa0172b764a99f2aa3711808bf64?v\u003d1715921620\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/center\u003e"}}]}