Given an array of integers A and a sum B, find all unique combinations in A where the sum is equal to B. The same repeated number may be chosen from A unlimited number of times.

**Note:**

**1.** All numbers will be positive integers.

** 2.** Elements in a combination (a1, a2, … , ak) must be in non-descending order. (ie, a1 ≤ a2 ≤ … ≤ ak).

**3.** The combinations themselves must be sorted in ascending order.

**Input:**

First line of input contains number of testcases T. For each testcase, there will be three lines of input, first of which contains N, size of array. Next line contains N space seperated integers, and the last line contains B.

**Output:**

For each testcase, print the sets enclosing a backet "(" and ")". No space between two sets. If no set can be formed with the given set, then print "Empty" (without quotes).

**Constraints:**

1 <= T <= 500

1 <= N <= 12

1 <= A[i] <= 9

1 <= B <= 30

**Example:**

**Input:**

3

4

7 2 6 5

16

11

6 5 7 1 8 2 9 9 7 7 9

6

4

2 4 6 8

8

**Output:**

(2 2 2 2 2 2 2 2)(2 2 2 2 2 6)(2 2 2 5 5)(2 2 5 7)(2 2 6 6)(2 7 7)(5 5 6)

(1 1 1 1 1 1)(1 1 1 1 2)(1 1 2 2)(1 5)(2 2 2)(6)

(2, 2, 2, 2)(2, 2, 4)(2, 6)(4, 4)(8)

**Explanation:
Testcase 1:** Required sets with sum equal to B (8) are as follows:

[2, 2, 2, 2]

[2, 2, 4]

[2, 6]

[4, 4]

[8]

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.

RatneshTiwari3 | 24 |

AnmolPassi | 20 |

Swords | 20 |

baranwalsuraj96 | 17 |

tarun711 | 16 |

Bishnu Dev Panda | 727 |

yk12 | 512 |

DevMittal | 472 |

okayboss | 458 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4921 |

Quandray | 4547 |

Login to report an issue on this page.