#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pb push_back
#define pp pop_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
ld pi=acos(-1);
ll mod=1e9+7;
void fast()
{
cin.sync_with_stdio(0) ;
cin.tie(0) ;
cout.tie(0);
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
if(a.first==b.first)
return b.second>a.second;
return a.first<b.first;
}
long long gcd(long long a,long long b)
{
if(a==0)
return b;
return gcd(b%a,a);
}
long long fp(ll b, ll p)
{
ll ans = 1;
while (p)
{
if (p % 2)
{
ans = (ans * b)%mod;
}
b = (b * b)%mod;
p /= 2;
}
return ans%mod;
}
bool isp(long long n)
{
if(n==1)
return false;
if(n==2||n==3)
return true;
if(n%2==0||n%3==0)
return false;
for(long long i=5;i*i<=n;i+=2)
if(n%i==0)
return false;
return true;
}
long long fc(long long n)
{
if(n==0)
return 1;
long long s=1;
for(int i=1;i<=n;i++)
s=s*i;
return s;
}
ll lcm(ll a,ll b)
{
ll m=gcd(a,b);
m=a/m*b;
return m;
}
#define MAX 10000001
ll primes[MAX] ;
bool sieve[MAX] ;
int l;
void genPrimes()
{
primes[l++] = 2 ;
long long i,j ;
for(j=4;j<MAX;j+=2) sieve[j] = true ;
for(i=3;i<MAX;i+=2)
{
if(sieve[i]==false)
{
primes[l++] = i ;
for(j=i*i;j<MAX;j+=i) sieve[j] = true ;
}
}
}
void N(ll n)
{
map<int,int>mp;
int od=0,ev=0;
ll tmp = sqrt(n),i ;
ll j = 0 ;
ll p[1000];
memset(p,0,sizeof(p));
for(i=0;primes[i]<=tmp;i++)
if(n % primes[i] == 0)
{
int cnt = 0 ;
while(n % primes[i] == 0)
{
cnt ++ ;
//cout<<" "<<primes[i]<<"\n";
n /=primes[i] ;
}
if(cnt%2)
od++;
else
ev++;
p[j++]=primes[i] ;
mp[primes[i]]=cnt;
tmp = sqrt(n) ;
}
if(n>1) {
p[j++]=n;
od++;
// cout<<" "<<n<<"\n";
mp[n]++;
}
sort(p,p+j);
for(int i=0;i<j;i++)
cout<<p[i]<<'^'<<mp[p[i]]<<" ";
// sort(p,p+j);
}
/*ll c=1e9+7;
ll modd(ll a,ll b)
{
ll rs=0;
a=a%c;
while(b)
{
if(b%2)
rs=(rs+a)%c;
a=(2*a)%c;
b/=2;
}
return rs;
}*/
int main() {
fast();
int tt=1;
cin>>tt;
for(int ts=1;ts<=tt;ts++)
{
int n,k;
cin>>n>>k;
int a[n+1],b[n+1],c[n+1];
a[0]=0,b[0]=0,c[0]=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=(a[i]+b[i-1])%k;
}
c[n]=a[n]%k;
map<int,int>mp;
mp[c[n]]++;
for(int i=n-1;i>0;i--)
{
c[i]=(c[i+1]+a[i])%k;
mp[c[i]]++;
}
int ans=0;
for(int i=1;i<n;i++)
{
int x=(k-b[i])%k;
mp[c[i]]--;
ans+=mp[x];
}
cout<<ans<<"\n";
}
return 0;
}
Copy