I tried representing dp[i] as the number of ways to reach amount i.
initial wrong code:
t = int(input())
for _ in range(t):
n = int(input())
coins = list(map(int, input().split()))
amount = int(input())
dp = [0 for _ in range(amount + 1)]
for coin in coins:
dp[coin] = 1
for i in range(1, amount + 1):
for coin in coins:
if i >= coin:
dp[i] += dp[i - coin]
print(dp[amount])