Given an array of N integers, using ‘+’ and ‘-‘ between the elements check if there is a way to form a sequence of numbers which evaluate to a number divisible by M.

**Input:**

The first line contains **T,** the number of test cases.For each test case, the first line contains an integer **n **denoting the size of the array **A**. Next line contains n-space separated integers and next line contains an integer **m** denoting the number from which divisibility needs to be checked.

**Output:**

For each test case, the output is 1 if divisible else 0.

**Constraints:**

1<=T<=100

1<=n<=50

1<=m<=10

**Note: **Sum of elements should be less than 1000.

**Example:
Input**

2

5

1 2 3 4 6

4

3

1 3 9

2

1

0

**Explanation:
1.**There is a valid sequence i. e., (1 - 2 + 3 + 4 + 6), which evaluates to 12 that is divisible by 4.

Author: Vanshika_pec

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.