#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define sl(x) scanf("%lld", &x)
#define mod 1000000007
#define mod1 1000000006
#define get getchar//_unlocked
#define INF 1000000000000000000LL
ll ans[100005];
ll dp[2005][2005];
ll cumDp[2005][2005];
ll a[100005];
ll cumAns[100005];
int main()
{
int t, n, k, i, j, l;
cin >> t;
while (t--) {
cin >> n >> k;
for (i = 1; i <= k; ++i)
cin >> a[i];
for (i = 1; i <= k; ++i) {
dp[1][i] = 1;
cumDp[1][i] = 1;
}
ans[1] = k;
cumAns[1] = k;
for (i = 2; i <= n; ++i) {
ans[i] = 0;
for (j = 1; j <= k; ++j) {
dp[i][j] = 0;
l = max(0LL, i-a[j]);
dp[i][j] = cumAns[i-1];
if (l)
dp[i][j] -= cumAns[l-1];
dp[i][j] -= (cumDp[i-1][j]);
if (l)
dp[i][j] += cumDp[l-1][j];
dp[i][j] %= mod;
if (dp[i][j] < 0)
dp[i][j] += mod;
cumDp[i][j] = cumDp[i-1][j] + dp[i][j];
if (cumDp[i][j] >= mod)
cumDp[i][j] -= mod;
if (!l) {
++dp[i][j];
++cumDp[i][j];
}
if (cumDp[i][j] >= mod)
cumDp[i][j] -= mod;
if (dp[i][j] >= mod)
dp[i][j] -= mod;
/*for (l = 1; l <= a[j] && i-l > 0; ++l) {
dp[i][j] += ans[i-l];
if (dp[i][j] >= mod)
dp[i][j] -= mod;
dp[i][j] -= dp[i-l][j];
if (dp[i][j] < 0)
dp[i][j] += mod;
}
if (l <= a[j]) {
++dp[i][j];
}*/
ans[i] += dp[i][j];
//cout << i << " " << j << " " << dp[i][j] << endl;
if (ans[i] >= mod)
ans[i] -= mod;
}
cumAns[i] = cumAns[i-1] + ans[i];
if (cumAns[i] >= mod)
cumAns[i] -= mod;
}
cout << ans[n] << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyB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OwogICAgICAgICAgICAgICAgZHBbaV1bal0gPSBjdW1BbnNbaS0xXTsKICAgICAgICAgICAgICAgIGlmIChsKQogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdIC09IGN1bUFuc1tsLTFdOwogICAgICAgICAgICAgICAgZHBbaV1bal0gLT0gKGN1bURwW2ktMV1bal0pOwogICAgICAgICAgICAgICAgaWYgKGwpCiAgICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdICs9IGN1bURwW2wtMV1bal07CiAgICAgICAgICAgICAgICBkcFtpXVtqXSAlPSBtb2Q7CiAgICAgICAgICAgICAgICBpZiAoZHBbaV1bal0gPCAwKQogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdICs9IG1vZDsKICAgICAgICAgICAgICAgIGN1bURwW2ldW2pdID0gY3VtRHBbaS0xXVtqXSArIGRwW2ldW2pdOwogICAgICAgICAgICAgICAgaWYgKGN1bURwW2ldW2pdID49IG1vZCkKICAgICAgICAgICAgICAgICAgICBjdW1EcFtpXVtqXSAtPSBtb2Q7CiAgICAgICAgICAgICAgICBpZiAoIWwpIHsKICAgICAgICAgICAgICAgICAgICArK2RwW2ldW2pdOwogICAgICAgICAgICAgICAgICAgICsrY3VtRHBbaV1bal07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoY3VtRHBbaV1bal0gPj0gbW9kKQogICAgICAgICAgICAgICAgICAgIGN1bURwW2ldW2pdIC09IG1vZDsKICAgICAgICAgICAgICAgIGlmIChkcFtpXVtqXSA+PSBtb2QpCiAgICAgICAgICAgICAgICAgICAgZHBbaV1bal0gLT0gbW9kOwogICAgICAgICAgICAgICAgLypmb3IgKGwgPSAxOyBsIDw9IGFbal0gJiYgaS1sID4gMDsgKytsKSB7CiAgICAgICAgICAgICAgICAgICAgZHBbaV1bal0gKz0gYW5zW2ktbF07CiAgICAgICAgICAgICAgICAgICAgaWYgKGRwW2ldW2pdID49IG1vZCkKICAgICAgICAgICAgICAgICAgICAgICAgZHBbaV1bal0gLT0gbW9kOwogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdIC09IGRwW2ktbF1bal07CiAgICAgICAgICAgICAgICAgICAgaWYgKGRwW2ldW2pdIDwgMCkKICAgICAgICAgICAgICAgICAgICAgICAgZHBbaV1bal0gKz0gbW9kOwoKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChsIDw9IGFbal0pIHsKICAgICAgICAgICAgICAgICAgICArK2RwW2ldW2pdOwogICAgICAgICAgICAgICAgfSovCiAgICAgICAgICAgICAgICBhbnNbaV0gKz0gZHBbaV1bal07CiAgICAgICAgICAgICAgICAvL2NvdXQgPDwgaSA8PCAiICIgPDwgaiA8PCAiICIgPDwgZHBbaV1bal0gPDwgZW5kbDsKICAgICAgICAgICAgICAgIGlmIChhbnNbaV0gPj0gbW9kKQogICAgICAgICAgICAgICAgICAgIGFuc1tpXSAtPSBtb2Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3VtQW5zW2ldID0gY3VtQW5zW2ktMV0gKyBhbnNbaV07CiAgICAgICAgICAgIGlmIChjdW1BbnNbaV0gPj0gbW9kKQogICAgICAgICAgICAgICAgY3VtQW5zW2ldIC09IG1vZDsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBhbnNbbl0gPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/py_compile.py", line 117, in compile
raise py_exc
py_compile.PyCompileError: File "prog.py", line 3
using namespace std;
^
SyntaxError: invalid syntax