1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: Problem C - Divisible Subsequences
* Link: http://uva.onlinejudge.org/contests/240-0682ae4a/p2.html
*
* @author Dennis Wilfert
* @version 1.0, 11/17/2009
*
* Status : Accepted
* Runtime: 0,45s user 0,10s system
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

StringTokenizer token;
int divisor, subseq, current, sum, div;

int[] divisors;

for (int i = Integer.parseInt(reader.readLine()); i > 0; i--) {
divisors = new int[1000000];
token = new StringTokenizer(reader.readLine());
divisor = Integer.parseInt(token.nextToken());
subseq = Integer.parseInt(token.nextToken());

token = new StringTokenizer(reader.readLine());
sum = div = 0;
divisors[0] = 1;

// Haben zwei Teilsummen den selben Rest, ist die Differrenz teilbar durch den Teiler
for (int j = 0; j < subseq; j++) {

current = Integer.parseInt(token.nextToken());

div = (div + current) % divisor;

sum += divisors[div];

divisors[div]++;

}
writer.println(sum);

}

writer.flush();
}
}