#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, N) for(int i = 0; i < N; i++)
#define FOR1e(i, N) for(int i = 1; i <= N; i++)
#define REP(i, M, N) for(int i = M; i < N; i++)
#define REPe(i, M, N) for(int i = M; i <= N; i++)
#define sc(N) scanf("%d", &N)
#define scsc(M, N) scanf("%d %d", &M, &N)
#define gt(s) getline(cin, s)
#define all(s) s.begin(), s.end()
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define ss stringstream
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ms(a, v) memset(a, v, sizeof a)
const int MAX = 1e5 + 1;
const int MOD = 1000000007;
int dr[] = {0, -1, 0, 1};
int dc[] = {1, 0, -1, 0};
inline int Pow(int b, int p) {if(!p) return 1; int sq = Pow(b, p >> 1); sq *= sq; if(p&1) sq *= b; return sq;}
inline int gcd(int a, int b) {if(!a) return b; return gcd(b % a, a);}
int t, n, k, arr[105];
ll dp[105][105];
ll solve(int i, int curK, ll val){
if(curK == k){
if(val % 9 == 0)
return val;
return -(1 << 62);
}
if(i == n) //we reached the end before concatinating K numbers.
return -(1 << 62);
ll &ret = dp[i][curK];
if(ret != -1)
return ret;
ret = -(1 << 62);
//(0 / 1): take it or leave it
return ret = max(ret, max(solve(i + 1, curK + 1, val * 10 + arr[i]), solve(i + 1, curK, val)));
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
sc(t);
while(t--){
scsc(n, k);
FOR(i, n)
sc(arr[i]);
sort(arr, arr + n, greater <int>());
ms(dp, -1);
ll ans = solve(0, 0, 0);
if(ans == -(1 << 62))
puts("-1");
else
printf("%lld\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGJpdHNldD4KI2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uZGVmIE9OTElORV9KVURHRQoJZnJlb3BlbigiaW4udHh0IiwgInIiLCBzdGRpbik7CiNlbmRpZgogICAgc2ModCk7CiAgICB3aGlsZSh0LS0pewogICAgICAgIHNjc2Mobiwgayk7CiAgICAgICAgRk9SKGksIG4pCiAgICAgICAgICAgIHNjKGFycltpXSk7CiAgICAgICAgc29ydChhcnIsIGFyciArIG4sIGdyZWF0ZXIgPGludD4oKSk7CiAgICAgICAgbXMoZHAsIC0xKTsKICAgICAgICBsbCBhbnMgPSBzb2x2ZSgwLCAwLCAwKTsKICAgICAgICBpZihhbnMgPT0gLSgxIDw8IDYyKSkKICAgICAgICAgICAgcHV0cygiLTEiKTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIHByaW50ZigiJWxsZFxuIiwgYW5zKTsKICAgIH0KCXJldHVybiAwOwp9Cg==