#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX 1024 #define MOD 1000000007 #define X first #define Y second using namespace std; typedef long long i64; typedef pair Pii; int a[MAX], dp[MAX][MAX]; inline void add(int& a, int b, int p = MOD) { if ((a += b) >= p) a -= p; } int solve(int n, int p) { for (int i = 1; i <= n; ++i) { a[i] %= p; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j < p; ++j) { add(dp[i][j], dp[i - 1][j]); add(dp[i][j], dp[i - 1][(j - a[i] + p) % p]); } } return dp[n][0]; } int main() { int t, n, p; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &p); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } printf("%d\n", solve(n, p)); } return 0; }