Robot Rock Band (Small)

Count quadruples with one element from each of four lists whose bitwise XOR equals K.

Medium5Hash mapBrute forceInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You manage Xorbitant, the world's first robot rock band. The band has four positions, and N robots audition for each position. No robot auditions for more than one position. Every robot carries a number, and several robots can carry the same number, just as two people can share a name.

Market research says the robot audience does not care how well the members play, how they look, or what the tabloids print about them. The audience checks one thing: whether the bitwise XOR of the four members' numbers equals a trendy number K.

Count the sets of four robots, one per position, that give the band this property. Stated precisely, you are given four lists A, B, C, D of N numbers each, and you must count the ways to pick aa from A, bb from B, cc from C, and dd from D so that abcd=Ka \oplus b \oplus c \oplus d = K. Here \oplus is the bitwise XOR operation.

Input

The first line holds the number of test cases T. T test cases follow. Each case begins with one line holding two space separated integers N and K. Four more lines follow, each with N space separated integers, the numbers of the robots auditioning for one position in the band.

Limits

  • 1T101 \le T \le 10
  • 0K1090 \le K \le 10^9
  • Every robot number is between 00 and 10910^9, inclusive.
  • 1N501 \le N \le 50

Output

For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the number of bands that meet the condition.

Note

In the first test case of the first example, the combined XOR has to be 3, so the robot taken from the second list must be 2 and the robot taken from the fourth list must be 1. Either of the two robots numbered 0 can be taken from the first list and from the third list, so 2×2=42 \times 2 = 4 bands meet the condition. All four bands read as (0, 2, 0, 1), but they count as different because the robots picked from the lists differ.