#P7466. [2017年杭电多校]Big Integer
[2017年杭电多校]Big Integer
Big Integer
Problem Description
Little Q likes positive big integers in base , but not all big integers. He doesn't like integers with zeroes, including leading zeroes. He is even particular with the occurrence of each digit. Formally it can be described as a matrix , for every digit from to , he doesn't like integers having exactly -digit when . He also can't accept any digit appearing more than times.
Little Q's taste changes every day. There are days in total, on -th day flipped( to and to ). Let denotes the number of big integers Little Q likes after -th day's change, where denotes the answer before all changes. Your task is to calculate the following thing :
Input
The first line of the input contains an integer , denoting the number of test cases. In each test case, there are integers $k,n,m(3\leq k\leq 10,1\leq n\leq 14000,1\leq m\leq 200)$ in the first line, denoting the base, the upper limit and the number of days. For the next lines, each line contains integers , denoting the matrix . For the next lines, each line contains integers , denoting a changed position in .
Output
For each test case, print a single line containing an integer, denoting the answer.
Sample Input
1
3 2 2
101
010
1 1
1 2
Sample Output
13
Hint
cnt(0)=4 : 112,121,211,2. cnt(1)=6 : 112,121,211,2,12,21. cnt(2)=3 : 2,12,21.
Source
2017 Multi-University Training Contest - Team 4