Under construction

Still being built. Things may change

Count Modulo 2

Time limit3.5sMemory limit1024 MB

Summary
Given N and a set A, count the length-N sequences of values from A that sum to S, modulo 2, with N and S up to 10^18.
Level

Medium7 of 10

Topics
Math, Dynamic programming, Number theory
Solved
No attempts yet

Problem

You are given KK distinct nonnegative integers A1,A2,⋯ ,AKA_1, A_2, \cdots, A_K. Count the number of sequences of NN nonnegative integers a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N that satisfy all of the following conditions, modulo 2.

  • a1+a2+⋯+aN=Sa_1+a_2+\cdots+a_N=S
  • For each ii (1≤i≤N1 \leq i \leq N), there exists an integer jj such that ai=Aja_i=A_j.

There are TT tests in one input file.

Input

Input is given from standard input in the following format:

TT

The description of each test is given in the following format, one test after another.

NN SS KK

A1A_1 A2A_2 ⋯\cdots AKA_K

Output

For each test, print the count modulo 2.

Constraints

  • 1≤T≤51 \leq T \leq 5
  • 1≤N≤10181 \leq N \leq 10^{18}
  • 0≤S≤10180 \leq S \leq 10^{18}
  • 1≤K≤2001 \leq K \leq 200
  • 0≤A1<A2<⋯<AK≤1050 \leq A_1 < A_2 < \cdots < A_K \leq 10^5
  • All values in input are integers.

Hint

In the first test, there are a total of 51 sequences that satisfy the conditions.

Examples1

  1. Example 1

    Input
    2
    5 10 3
    1 2 3
    1000000000000000000 25453321771239381 10
    0 1683 21728 31623 35054 37834 39329 56842 68603 74742
    
    Expected output
    1
    0