A string made only of ( and ) is a bracket string. Among bracket strings, a correct bracket string is defined as follows.
A bracket string that is not correct is called an incorrect bracket string. (())(), ()()(), (()()) are correct bracket strings, and ())((), (, (()()() are incorrect bracket strings.
A string S is periodic if some prefix of S that is neither empty nor S itself is also a suffix of S. A string with no such prefix is aperiodic. abcabcab, ()(, aaaaaa are periodic, and abcd, (())(), a are aperiodic.
Write a program that counts the bracket strings of length L satisfying the given conditions.
The first line contains four integers p, q, m, Q separated by spaces. (0≤p≤1, 0≤q≤1, 1≤m≤106, 1≤Q≤105)
Each of the next Q lines contains one natural number L. (1≤L≤106)
Let AL be the set of all bracket strings of length L, let BL be the set of incorrect bracket strings of length L, and let CL be the set of aperiodic bracket strings of length L. If p=0 then P=AL, and if p=1 then P=BL. If q=0 then R=AL, and if q=1 then R=CL.
In other words, for p=0, q=0 count the bracket strings of length L; for p=1, q=0 count the incorrect ones; for p=0, q=1 count the aperiodic ones; for p=1, q=1 count the ones that are incorrect and also aperiodic.
For each L, print ∣P∩R∣ modulo m on its own line. Print Q lines in the order the lengths are given.
Among the bracket strings of length 4, exactly two are correct, ()() and (()), so 16−2=14 of them are incorrect. The aperiodic bracket strings of length 4 are (((), (()), ())), )(((, ))((, )))(, six in total, and only (()) among them is correct. So 5 bracket strings of length 4 are incorrect and aperiodic at the same time.