Under construction

Still being built. Things may change

Coins

Interview

Time limit1sMemory limit128 MB

Summary
Count the unordered combinations of up to 20 coin values that sum to the target amount M.
Level

Medium4 of 10

Topics
Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Korean coins come in denominations of 1, 5, 10, 50, 100, and 500 won. Picking several coins adds up to an integer amount, and the same amount usually has more than one combination. For example, 30 won is thirty 1 won coins, or two 10 won coins together with two 5 won coins.

Given the denominations, write a program that counts how many ways there are to make a given amount. Each denomination can be used any number of times, and two selections that differ only in the order the coins were picked count as one way.

Input

The first line has the number of test cases TT (1≤T≤101 \le T \le 10). Each test case takes three lines. The first line has the number of denominations NN (1≤N≤201 \le N \le 20). The second line has the NN coin values in increasing order, separated by spaces. Every value is an integer between 1 and 10000, and no value is given twice. The third line has the amount MM (1≤M≤100001 \le M \le 10000) to make.

The number of ways is always smaller than 231−12^{31} - 1.

Output

For each test case, print the number of ways to make the amount MM with the given NN denominations, one per line.

Examples1

  1. Example 1

    Input
    3
    2
    1 2
    1000
    3
    1 5 10
    100
    2
    5 7
    22
    
    Expected output
    501
    121
    1