Under construction

Still being built. Things may change

Robot Rock Band (Large)

Interview

Time limit7sMemory limit512 MB

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

Medium5 of 10

Topics
Hash map, Bit manipulation
Solved
No attempts yet

Problem

You manage Xorbitant, the world's first robot rock band. The band has four positions, and NN robots audition for each position. No robot auditions for more than one position. Every robot carries a number, and two robots can carry the same number, the way 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 the trendy number KK.

How many different sets of four robots, one per position, give the band that property? Put another way, four lists AA, BB, CC, DD hold NN numbers each. Count the ways to pick one number aa from AA, one number bb from BB, one number cc from CC, and one number dd from DD so that a⊕b⊕c⊕d=Ka \oplus b \oplus c \oplus d = K, where ⊕\oplus is bitwise XOR.

Input

The first line holds the number of test cases TT. Each test case starts with a line holding two space separated integers NN and KK. Four lines follow. Each holds NN space separated integers, the numbers of the robots auditioning for one position. The four lines give the lists AA, BB, CC, DD in that order.

Limits

  • 1≤T≤101 \le T \le 10
  • 0≤K≤1090 \le K \le 10^9
  • Every robot number is between 00 and 10910^9.
  • 1≤N≤10001 \le N \le 1000

Output

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

Hint

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

Examples2

  1. Example 1

    Input
    2
    2 3 
    0 0
    2 0
    0 0
    0 1
    2 0
    1 10
    1 10
    1 10
    1 10
    
    Expected output
    Case #1: 4
    Case #2: 8
    
  2. Example 2

    Input
    3
    1 0
    0
    0
    0
    0
    1 5
    1
    2
    4
    3
    1 4
    1
    2
    4
    3
    
    Expected output
    Case #1: 1
    Case #2: 0
    Case #3: 1