Redistribution of Digits

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

You are required to form numbers based on a given set of digits. Each number is also provided with an upper bound. Each digit from the given set must be used exactly once. If the set does not contain a digit, you are not allowed to use it.

입력

First line contains an integer tt --- the number of tests.

Each of the next tt lines contains a string ss --- a given set of digits, integer nn --- quantity of numbers which should be formed and nn integers a_ia\_i --- upper bounds for numbers. The digits for all numbers a_ia\_i are given in a non-increasing order starting from the most significant digit. The set of digits and the numbers a_ia\_i do not contain a digit 00.

출력

You are required to output tt lines containing the given quantity of numbers corresponding the conditions above. If a solution does not exist you should print "-1". If there are multiple solutions, you may output any of them.

제한

  • 1t10001 \le t \le 1000
  • 1s5001 \le |s| \le 500
  • 1n501 \le n \le 50
  • 1a_i1091 \le a\_i \le 10^9