You have spent the last twenty years studying competitive programming. Now only one exam stands between you and becoming the very best. You open the exam paper and see a single problem.
You are given bags, each containing some distinct stones of varying weights. From each bag, you can pick at most one stone. You are also given a target fraction . You have to pick stones so that their average weight is exactly . How many ways can this be done so? Output the count of such ways.
Note that two ways of picking stones are different if there is some bag from which you pick a stone in one way but not in the other or if from some bag you pick different stone (different stones can have same weight).
First line of input will have a integer denoting the number of independent testcases.
Each testcase will start with a line containing one integer, denoting number of bags.
Next lines will contain the description of bags.
Each line will contain several space separated integers. They will start with an integer denoting the number of stones in the bag. Next integers will denote the weights of the stones in the bag. Final line of the testcase will contain two integers and denoting the target fraction .
weight of each stone
Product of over all bags in a testcase will be at most
For each testcase output the count of ways in a single line.
2 2 2 1 1 2 1 1 1 1 3 2 2 3 3 1 4 2 3 3 2 1 5 2
In the first testcase, among the nine possible combinations of picking stones, one picks none of the stones and other eight picks stones in such a way that the average is exactly .