We work only with multi-variable polynomials of degree at most 4 over 26 variables, one variable for each lowercase English letter. Here is one such polynomial:
aber+aab+c
Given a string S, evaluate the polynomial on it. Every variable is replaced by the number of times that letter appears in S, and the result is called p(S).
For example, take the polynomial above and let S be abracadabra edgar. It contains six a's, two b's, one c, one e, and three r's, so
p(S)=6×2×1×3+6×6×2+1=109.
You are given a dictionary of distinct words made of lowercase letters only. A string S is a d-phrase if
S = "S1 S2 S3 ... Sd"
where each Si is a word from the dictionary. That is, S is d dictionary words joined by single spaces, and the same word may be used more than once. Given K with K≤10, compute the sum of p(S) over all d-phrases, for every d with 1≤d≤K. The sums get large, so report each one modulo 10009.
The first line contains the number of test cases T. Each test case has this format:
A polynomial is always written as a sum of terms, and each term is a product of variables. at is written as t copies of the letter a concatenated, so a2b is written as aab. The variables inside a term are always in non-decreasing lexicographic order.
Constraints
+, and it neither starts nor ends with +. Each p has at most 5 terms. Each term has at least 1 and at most 4 lowercase letters in non-decreasing order. No two terms of one polynomial are equal.For each test case, print a single line in the form
Case #X: sum1 sum2 ... sumK
where X is the case number starting from 1, and the i-th value is the sum of p(S) over all i-phrases, taken modulo 10009.