might or might not had been used during making of this problem.
In this problem functions are implictly assumed to have a single non-negative integer as an argument and produce a single non-negative integer as a result.
f is a function. f(x)=1+2+…+x. More formally, f(x) is the sum of all positive integers less than or equal to x.
s_k is a family of functions. s_0 is an identity function (s_0(x)=x) and s_k(x)=s_k−1(f(x)+k).
You are given t test cases. i-th test case contains three integers x_i, k_i and p_i. For each test case find an integer m_i such that −1≤m≤p_i−1, s_k_i(x_i)modp_i≡m_i. You may use m_i=−1 no more than 20 times. p_i are pairwise distinct. Note, that amodp≥0, where a is an arbitrary integer, so m_i=−1 is correct for any particular test case.
Why would you do that? It's simple. Finding correct answers is easy and conformist. On the other hand, finding incorrect answers is challenging and original. However, in this problem it's a bit too challenging, because of p=1 case. So you decided, that you will skip some test cases with m_i=−1 wildcard. Sounds reasonable (not).
The first line of input contains a single integer t (1≤t≤5000) --- the number of test cases.
t lines follow. i-th of them contains three integers x_i,k_i,p_i (1≤x_i≤109,0≤k_i≤105,1≤p_i≤104).
It is guaranteed that ∀_i=jp_i=p_j.
Output t integers. i-th of them should be equal to m_i.
The number of indices i such that m_i=−1 should not exceed 20.