Digits and Fun

0

0 votes
Medium
Problem

Given a set of N digits, find the kth smallest number that can be formed using them such that the sum of its digits is prime. If the answer does not exists or is greater than 1018 print 1.

Input:
First line consists of a single integer T denoting the number of test cases.
Second line consists of a single integer denoting N.
Third line consists of N space separated numbers denoting the set of digits. Fourth line consists of a single integer denoting k.

Output: Print the required answer in a new line for each test case.

Constraints:
1N9
1k1018

Sample Input
1
3
1 2 3
1
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?