{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eAs an astronomer, Alice pilots her spaceship to observe an unknown object in the universe. This object can be viewed as a point in the space in a common theoretical model since its size is significantly smaller than the viewing distance.\u003c/p\u003e\n\u003cp\u003eBuilding a space rectangular coordinate system centred at the object, a possible perfect observing position is such which locals at an integral point. Alice records the number of perfect observing positions whose viewing distances are equal to $d\\in \\mathbb{Z}$ as $f_d$.\u003c/p\u003e\n\u003cp\u003eNow, given a permitted range $[L,R]$ of viewing distance, a test coefficient $K$ and a large prime number $P$, you are asked to calculate $\\Big(\\sum\\limits_{d\u003dL}^{R} (f_d\\text{ xor } K)\\Big)\\pmod{P}$ to explore the risk factor.\u003c/p\u003e\n\u003ch3\u003eInput\u003c/h3\u003e\n\u003cp\u003eThe first line contains an integer $T~(1\\le T\\le 10)$ representing the number of test cases.\u003c/p\u003e\n\u003cp\u003eFor each test case, an only line contains four integers $L, R, K$ and $P$ described as above, where $0\\le L\\le R\\le 10^{13}, 0\\le K\\le 10^{18}$, the prime number $P$ satisfies $P\\le 3\\times 10^{13}$ and $R-L+1\\le 10^6$.\u003c/p\u003e\n\u003ch3\u003eOutput\u003c/h3\u003e\n\u003cp\u003eFor each test case, print a line which contains an integer representing the risk factor inquired.\u003c/p\u003e"}},{"title":"Sample 1","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\n1 1 0 11\n1 1 1 11\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\n7\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}}]}