9709: Broken LED Lights

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

There is an ancient tall building that uses LED light tubes in the elevator to display the floor numbers. However, due to budget constraints for maintenance, the management is trying to reduce the number of floors the elevator can stop at and then discard unnecessary LED light tubes.

Currently, the number of floors the elevator can stop at has been determined, and the task of reducing the LED light tube wiring has been assigned to you. You know that the building has 10m floors, with floor numbers ranging from 000 to (10m-1) and displayed as numbers of length mmm (which may be left-padded with zeros). For each digit of the floor number, there were originally 777 light tubes, as shown in the figure below, that would flexibly turn on and off according to the required displayed number.


Now, nnn floors have been selected to continue supporting stops, and the elevator will only display these nnn floor numbers while moving and stopping. Your task is to minimize the number of light tubes that need to remain operational so that the on and off states of these tubes can be used to determine which of the nnn possible numbers the stopping floor corresponds to. Your time is very precious, so please calculate the minimum number of light tubes that need to remain operational as soon as possible.

输入格式

The first line contains an integer TTT (1≤T≤1001 \leq T \leq 1001T100), indicating the number of test cases.
Then follow TTT test cases. For each test case:
The first line contains two integers nnn and mmm (1≤n≤1001 \leq n \leq 1001n100, 1≤m≤31 \leq m \leq 31m3).
The second line contains nnn distinct integers x1,x2,…,xnx_1, x_2, \ldots, x_nx1,x2,,xn (0<=x<10m), representing the selected floor numbers. It is guaranteed that each floor number has exactly mmm digits.
It is also guaranteed that the sum of nnn over TTT test cases does not exceed 103.

输出格式

For each test case, output an integer in one line, representing the minimum number of light tubes that need to remain operational.

输入样例 复制

3
10 1
0 1 2 3 4 5 6 7 8 9
5 2
01 02 05 08 11
1 3
012

输出样例 复制

5
3
0

数据范围与提示

For the second case of the example, one of the possible solutions is listed below.
The original states:

After reduction: