{"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\"\u003eRuirui and Doc are playing an interesting game on a chessboard with $n$ rows and $m$ columns. The rows are numbered from $1$ to $n$ from top to bottom, and the columns are numbered from $1$ to $m$ from left to right. There are some broken grids on the chessboards, which a chess cannot move in. Firstly, Doc gives Ruirui a sequence of commands, each command is of one of four following forms:\u003cbr\u003e\u003cbr\u003e$\\cdot$\u003cb\u003eMove Up\u003c/b\u003e: moving from grid $(x,y)$ to grid $(x-1,y)$;\u003cbr\u003e$\\cdot$\u003cb\u003eMove Down\u003c/b\u003e: moving from grid $(x,y)$ to grid $(x+1,y)$;\u003cbr\u003e$\\cdot$\u003cb\u003eMove Left\u003c/b\u003e: moving from grid $(x,y)$ to grid $(x,y-1)$;\u003cbr\u003e$\\cdot$\u003cb\u003eMove Right\u003c/b\u003e: moving from grid $(x,y)$ to grid $(x,y+1)$.\u003cbr\u003e\u003cbr\u003eThen Ruirui puts a single chess on a grid of the chessboard\u003cbr\u003e\u003cbr\u003eRuirui will move the chess by Doc\u0027s commands in sequence. If the chess will be out of boarder or in a broken grid after a move, she omits this command and \\textbf{go on} to consider the next one until the last command. Now Ruirui wants to find the grid which the chess will be in the end.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains a single integer $T~(1\\le T\\le 10)$, which indicates the number of test cases. Then $T$ test cases follow.\u003cbr\u003e\u003cbr\u003eFor each test case, the first line contains $4$ integers $n,m,o$ and $l~(1\\le n,m,o,l\\le 1000)$ representing the number of rows, the number of columns, the number of broken grids and the length of Doc\u0027s command sequence.\u003cbr\u003e\u003cbr\u003eNext $o$ lines, each line contains two integers $i$ and $j$ describing the position of broken grid.\u003cbr\u003e\u003cbr\u003eThe last line contains Doc\u0027s command sequence, it\u0027s a string of length $l$ with each character being one of $\\{``U\",``D\",``L\",``R\"\\}$ denoting Move Up, Move Down, Move Left and Move Right respectively."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, for each unbroken grid $(i,j)$, assume a chess started at $(i,j)$ would stop at $\\left(x(i,j),y(i,j)\\right)$, output the sum of $\\left(i-x(i,j)\\right)^2 + \\left(j-y(i,j)\\right)^2$ (over all unbroken $(i,j)$)."}},{"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\u003e2\r\n5 5 5 5\r\n2 3\r\n5 1\r\n5 5\r\n4 4\r\n3 5\r\nRRRLR\r\n10 10 10 10\r\n2 6\r\n3 8\r\n7 2\r\n5 3\r\n4 3\r\n3 2\r\n7 9\r\n6 8\r\n9 10\r\n10 6\r\nDLLDRRURLR\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: 49\r\nCase #2: 241\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}