Digidivisible Numbers

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Let's call a number digidivisible in base BB, if it is divisible by all digits in its base BB representation. For example, 728_10728\_{10} is divisible by 77, 22 and 88, so it is digidivisible in base 1010, and number 264_8=180_10264\_8 = 180\_{10} is divisible by 22, 66 and 44, so it is digidivisible in base 88.

You are given integers BB and nn, and some set of allowed digits from 11 to B1B-1. Find the number of digidivisible numbers consisting of nn digits in base BB, only containing these allowed digits. Solve this problem for some fixed nn and BB and for multiple sets of allowed digits.

입력

The first line contains two integers BB and nn (2B102 \le B \le 10; 1n1091 \le n \le 10^9). The second line contains an integer tt (1t2B111 \le t \le 2^{B-1} - 1) --- the number of sets of allowed digits you need to solve this problem for.

Then, tt lines follow, ii-th line contains a single string s_is\_i, consisting of BB zeros and ones. If s_i,k=1s\_{i,k} = 1 (indices begin with 0), then digit kk is allowed, otherwise digit kk is forbidden. Each set has at least one allowed digit, and digit 00 is always forbidden. All tt sets are distinct.

출력

For each one of the tt sets print the answer in a separate line. Because the result might be huge, print it modulo 999;999;001999\\;999\\;001.

힌트

Total number of 3-digit digidivisible numbers in base 10 is 5656. If we only allow even digits, then there are 17 numbers left: 222, 224, 244, 248, 264, 288, 424, 444, 448, 488, 624, 648, 666, 824, 848, 864, 888.