**Note: The only difference between this and [Chapter 1](https://www.facebook.com/codingcompetitions/hacker-cup/2022/round-3/problems/E1) is that here, marble locations depend on previous answers.** There are \(N\) rubber bands on an infinite 2D peg board. The \(i\)th rubber band is initially shaped as a [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) of \(M_i\) integer vertices, \((X_{i,1}, Y_{i,1}),\) \(\ldots,\) \((X_{i,M_i}, Y_{i,M_i})\) in clockwise order. No two rubber bands touch or cross each other, though each rubber band may be fully enclosed in another. Other than their initial layout, all rubber bands look identical. You are given \(Q\) queries, the \(i\)th of which involves a red and blue marble shaped as a circle with radius \(1\), centered at points \((A_i, B_i)\) and \((C_i, D_i)\) respectively. The marbles do not touch each other, or any rubber bands. Formally, \((A_i, B_i)\) and \((C_i, D_i)\) are more than \(2\) units away from each other, and each more than \(1\) unit away from any rubber band. Query \(i\) asks whether you can roll the marbles and continuously move/deform rubber bands so: - the red marble ends up at \((C_i, D_i)\), - the blue marble ends up at \((A_i, B_i)\), - the final state of all rubber bands looks identical to the initial state (one rubber band may end up in place of another, but must end up having the exact same vertices), and - rubber bands never touch/cross, and the marbles never touch each other or any rubber band. For example, the first sample case and the fifth query of the second case can be solved as follows: {{PHOTO_ID:781832356415299|WIDTH:700}} Let \(R_i = 1\) if the answer to the \(i\)th query is "yes", else \(R_i = 0\). Please find the sum of \(R_1, ..., R_Q\). **You'll only be given \(A_1\), \(B_1\), \(C_1\), \(D_1\) directly, and must compute the remaining query points given values \(A_i'\), \(B_i'\), \(C_i'\), \(D_i'\) for \(i \gt 1\) along with an array \(E_{1..Q}\), as follows:** \[A_i\ := A_i'\ \oplus \ (R_1*E_1)\ \oplus \,\cdots\, \oplus\ (R_{i-1}*E_{1-1})\] **where \(\oplus\) is the bitwise XOR operator, with \(B_i\), \(C_i\), and \(D_i\) computed similarly. In other words, if the answer to the \(i\)th query is "yes", XOR all future query coordinates by \(E_i\).** # Constraints \(1 \le T \le 95\) \(1 \le N \le 200{,}000\) \(3 \le M_i \le 250{,}000\) \(3 \le \sum_{i=1}^{N} M_i \le 800{,}000\) \(1 \le Q \le 500{,}000\) \(0 \le X_{ij}, Y_{ij} \le 10^9\) \(0 \le A_i, B_i, C_i, D_i \le 10^9\) \(0 \le A_i', B_i', C_i', D_i', E_i \le 10^9\) The sum of \(M_i\) across all test cases is at most \(3{,}000{,}000\). The sum of \(Q\) across all test cases is at most \(2{,}000{,}000\). # Input Format Input begins with an integer \(T\), the number of test cases. For the \(i\)th test case, there is first a line containing a single integer \(N\). Then, \(N\) descriptions of polygons follow, the \(i\)th of which consists of two lines: the first containing a single integer \(M_i\) and the second containing \(2*M_i\) space-separated integers \(X_{i,1}\), \(Y_{i,1}\), \(\ldots\), \(X_{i,M_i}\), \(Y_{i,M_i}\). Then, there is a line containing a single integer \(Q\). Then, \(Q\) lines follow, the \(i\)th of which contains five space-separated integers, either \(A_1\), \(B_1\), \(C_1\), \(D_1\), \(E_1\) (if \(i = 1\)), or \(A_i'\), \(B_i'\), \(C_i'\), \(D_i'\), \(E_i\) (if \(i \gt 1\)). # Output Format For the \(i\)th test case, print `"Case #i: "` followed by a single integer, the sum \(R_1 + ... + R_Q\). # Sample Explanation *Note: The samples below are the same as those in chapter 1, only encoded with the scheme above.* In the first case, the only query is possible, as depicted above on the left. In the second case, \(R = [1, 1, 0, 0, 1, 1, 0]\). In the third case, the only query is not possible as one marble is inside the rubber band, while the other is outside. If the marbles swap places, then the rubber band will be surrounding the wrong marble.