Mike and Photographic Memory
Submissions: 270   Accuracy:

31.87%

  Difficulty: Medium   Marks: 4

Mike is a lawyer with the gift of photographic memory. He is so good with it that he can tell you all the numbers on a sheet of paper by having a look at it without any mistake. Mike is also brilliant with subsets so he thought of giving a challange based on his skill and knowledge to Rachael. Mike knows how many subset are possible in an array of N integers. The subsets may or may not have the different sum. The challenge is to find the maximum sum produced by any subset under the condition:  
The elements present in the subset should not have any digit in common.

Note: Subset {12, 36, 45} does not have any digit in common and Subset {12, 22, 35 } have digits in common.
Rachael find it difficult to win the challenge and is asking your help. Can you help her out in winning this challenge?

Input:

First Line of the input consist of an integer T denoting the number of test cases. Then T test cases follow. Each test case consist of a numbe N denoting the length of the array. Second line of each test case consist of N space separated integers denoting the array elements.

Output:

Corresponding to each test case, print output in the new line.

Constraints:

1 <= T <= 100
1 <= N <= 100
1 <= array elements <= 100000

Example:

Input

1
3
12 22 35

Output

57

Explanation

Subset which gives maximum sum is {22 , 35}

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Chaudhary gfg


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.