#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int maxn=5e4+5;
const int maxd=1e6+5;
int main()
{
int T;
scanf("%d",&T);
int num[maxd];
while(T--)
{
memset(num,0,sizeof(num));
LL d,n;
scanf("%lld%lld",&d,&n);
LL sum[maxn];
sum[0]=0;
LL solve=0;
for(int i=1;i<=n;i++)
{
LL k;
scanf("%lld",&k);
//if(k%d==0) solve++;
sum[i]=(sum[i-1]+1l*k%d)%d;
if(sum[i]==0) solve++;
if(num[sum[i]]) {
solve+=1l*num[sum[i]];
num[sum[i]]++;
}
else {
num[sum[i]]++;
}
}
printf("%lld\n",solve);
}
return 0;
}