Generate, Sort and Search We have the following recursive function:

f(1) = x f(n) = (a·f(n−1)+c)modm, withn≥2,n∈Z+ Remember that the operation mod calculates the remainder of the integer division. With the previous recursive function you should generate a sequence containing the first n elements, which are: f(1), f(2), f(3), f(4), ..., f(n). Then, you should sort those numbers in ascending order (with respect to its value), so you can tell which number is located in the i-th position of the sorted sequence. Input There are several test cases. The first line of each test case has six integer numbers: a, c, m, x, q, n separatedbyspaces(2≤a<m,0≤c<m,3≤m≤103,0≤x<m,1≤q≤104,1≤n≤108). The remaining lines of each test case have q integer numbers. Each one corresponds to the position in the sorted sequence whose value wants to be known. Output For each query you should print a single line containing the integer number in the i-th position of the sorted sequence. Sample Input 7 4 9 3 5 10 2 10 3 9 4 Sample Output 1 8 2 7 3