Teacher Mai has an infinite periodic binary string S with index counting from 0. That means S=TTTT..., where T is the period of string S. For example, T="101", then S="101101101101..."
S[l,r] is the sub-string of S. We define f[l,r] is the value when regarding S[l,r] as a binary number.
Please count the number of binary strings T with length k, where T is the period of string S, satisfying the condition: f[l,r]=x (mod p).
The number can be very large, just output the number modulo 1000000007 (10^9+7).