1. 

package acm_11087_divisibility_testing;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;

/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_11087_divisibility_testing
* Link:
*
* @author Martin Lambeck
* @version 1.0, 14.10.2010
*
* Method : modulo restklassen
* Status : Accepted
* Runtime: 2.336
*/


public class Main
{
static Scanner sc = new Scanner(System.in);
static ArrayList<TreeSet<Integer>> lst = new ArrayList<TreeSet<Integer>>(501);
static int tcase = 0;

public static void main(String... args)
{

for (int i = 0; i < 500; i++)
lst.add(new TreeSet<Integer>());


int cases = sc.nextInt();

for (int i = 0; i < cases; i++)
testcase();
}

public static void testcase()
{
int n = sc.nextInt();
int k = sc.nextInt();

int count = 0;

for (int i = 0; i < k; i++)
lst.get(i).clear();

for (int i = 0; i < n; i++)
{
int m = sc.nextInt();
int mod = ((m % k) + k) % k;

if (((m+m) % k == 0) && lst.get(mod).contains(m))
count++;

lst.get(mod).add(m);
}



for (int i = 0; i < k; i++)
{
TreeSet<Integer> lo = lst.get(i);
TreeSet<Integer> hi = lst.get(i==0 ? 0 : k-i);

Iterator<Integer> hii = hi.iterator();

int hn = Integer.MIN_VALUE;
int hpos = -1;

for (Integer ln : lo)
{
while((hn <= ln) && hii.hasNext())
{
hn = hii.next();
hpos++;
}

if (hn > ln)
count += hi.size() - hpos;
}
}

System.out.printf("Case %d: %d%n", ++tcase, count);
}
}