🏡 index : github.com/captn3m0/codechef.git

---
{"languages_supported":{"0":"NA"},"title":"E4","category":"NA","old_version":true,"problem_code":"E4","tags":{"0":"NA"},"layout":"problem"}
---

<h3> All submissions for this problem are available. </h3><h3>A tutorial for this problem is available <a title="here" href="/wiki/tutorial-quadratic-equations">here</a>.</h3>
<p>Knowing Johnny's mathematical talent, our teacher has prepared a new interesting problem for him, hoping he will enjoy solving it. The problem description is given below.</p>
<p>"There is a rectangular room of length l and width w (l and w are integers). The length and width of the room  fulfill the relation l=Aw+B, where A and B are given integer constants. The room is divided into square cells of unit dimensions. You have observed that, after adding an integer C to the number of cells in the room, the number of cells becomes divisible by the prime number P. Find all the possible values of the width of the room."</p>
<p> </p>
<h3>Input</h3>
<p>The first line contains t, the number of test cases (about 10000). Then t test cases follow. Each test case is given in one line containing 4 integers A, B, C and P (2  P &lt; 10<sup>6</sup>, 0 &lt; A &lt; P, 0  B,C &lt; P).</p>
<p>P is always a prime number.</p>
<h3>Output</h3>
<p>For each test case, write the result in one line. The first number K is the number of solutions. Then K numbers X<sub>1</sub>, X<sub>2</sub>, ...,X<sub>K</sub> follow (0  X<sub>i</sub> &lt; P), which are the solutions to the corresponding problems.</p>
<h3>Example</h3>
<pre><b>Input:</b>
2
1 1 0 2
1 2 2 3

<b>Output:</b>
2 0 1
0
</pre>
<p></p>