You are given an integer sequence $$$a_0, a_1, a_2, \dots$$$, in which the first two elements $$$a_0$$$ and $$$a_1$$$ are given, and for $$$i \ge 2$$$, the elements are specified by the recurrent formula $$$a_i = (A\cdot a_{i-1} + B \cdot a_{i-2}) \bmod M$$$.
The period of a sequence is a positive integer $$$T$$$ such that, starting with some $$$i_0$$$, for any $$$i \ge i_0$$$, it holds that $$$a_i = a_{i+T}$$$. Find the smallest period of the given sequence.
The first line contains one integer $$$t$$$ ($$$1\le t \le 100$$$), the number of test cases.
Each test case contains $$$5$$$ integers $$$M$$$, $$$a_0$$$, $$$a_1$$$, $$$A$$$, $$$B$$$ on a single line ($$$2 \le M \le 10^9$$$; $$$0 \le a_0, a_1, A, B \lt M$$$).
For each test case, print a single positive integer, the smallest period of the given sequence.
It can be shown that under the given constraints, the answer always exists and is not greater than $$$10^{18}$$$.
93 1 1 1 13 0 1 2 27 0 0 3 410 1 2 3 010 1 2 0 311 1 1 6 612 4 3 2 115 3 5 5 219 8 2 18 14
8 3 1 4 8 1 8 24 171
Sequences in the first 6 test cases (repeating subsequence is bolded):