Divisible Group Sums

Given a list of N numbers you will be allowed to choose any M of them. So you can choose in MN ways. You will have to determine how many of these chosen groups have a sum, which is divisible by D. Input The input file contains maximum ten sets of inputs. The description of each set is given below. ThefirstlineofeachsetcontainstwointegersN (0<N ≤200)andQ(0<Q≤10). HereN indicates how many numbers are there and Q is the total no of query. Each of the next N lines contains one 32 bit signed integer. Our queries will have to be answered based on these N numbers. Next Q lines contain Q queries. Each query contains two integers D (0 < D ≤ 20) and M (0 < M ≤ 10) whose meanings are explained in the first paragraph. Input is terminated by a case whose N = 0 and Q = 0. This case should not be processed. Output For each set of input, print the set number. Then for each query in the set print the query number followed by the number of desired groups. See sample output to know the exact output format. Sample Input 10 2 1 2 3 4 5 6 7 8 9 10 51 52 51 2 3 4 5 6 62 00 ()

2/2 Sample Output SET 1: QUERY 1: 2 QUERY 2: 9 SET 2: QUERY 1: 1