{"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\"\u003eRecently, Alice and Bob are working on a resource-sharing computation model. In this model, there are two processing units, and a memory space which could be represented as unlimited linear grids $ \\ldots, A_{-3}, A_{-2}, A_{-1}, A_0, A_1, A_2, A_3, \\ldots$. Each processing units has a pointer to mark exactly one grid in the memory. In each clock turn, the pointer would stay at the current grid, move the pointer one grid forward, or move the pointer one grid backward. In their work, Alice and Bob would submit their codes, and their programs would start at the same time. Initially, both pointers would be located at a random grid, and move according to a set of instructions. If both pointers are at the same grid at the same time, the confliction counter would plus one and record it(If their initial grids are the same, the counter would still record it). Now it is your job to find the maximum conflictions the counter could record.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line is the number of test cases.\u003cbr\u003eFor each test case, the first is an integer $N_{Alice} (N_{Alice} \\leq 100000)$, donating the length of the instructions of Alice.\u003cbr\u003e\u003cbr\u003eThe next $N_{Alice}$ lines describe Alice`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.\u003cbr\u003e\u003cbr\u003eThe next line is an integer $N_{Bob} (N_{Bob} \\leq 100000)$, donating the length of the instructions of Bob.\u003cbr\u003e\u003cbr\u003eThe next $N_{Bob}$ lines describe Bob`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.\u003cbr\u003e\u003cbr\u003eSuppose $L_{Alice}$ equals the sum of all $t$ in Alice\u0027s program, and $L_{Bob}$ equals the sum of all $t$ in Bob\u0027s program.\u003cbr\u003eIt is guaranteed $L_{Alice} \u003d L_{Bob}$ and $L_{Alice}, L_{Bob} \\leq 10^{18}$.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output a line containing the maximum conflictions."}},{"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\n1\r\n1 2\r\n2\r\n1 1\r\n-1 1\r\n1\r\n0 6\r\n4\r\n-1 2\r\n1 1\r\n-1 2\r\n1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}