CF2050A.Line Breaks

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Line Breaks

Kostya has a text ss consisting of nn words made up of Latin alphabet letters. He also has two strips on which he must write the text. The first strip can hold mm characters, while the second can hold as many as needed.

Kostya must choose a number xx and write the first xx words from ss on the first strip, while all the remaining words are written on the second strip. To save space, the words are written without gaps, but each word must be entirely on one strip.

Since space on the second strip is very valuable, Kostya asks you to choose the maximum possible number xx such that all words s1,s2,,sxs_1, s_2, \dots, s_x fit on the first strip of length mm.

Input

The first line contains an integer tt (1t10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains two integers nn and mm (1n501 \le n \le 50; 1m5001 \le m \le 500) — the number of words in the list and the maximum number of characters that can be on the first strip.

The next nn lines contain one word sis_i of lowercase Latin letters, where the length of sis_i does not exceed 1010.

Output

For each test case, output the maximum number of words xx such that the first xx words have a total length of no more than mm.

Samples

5
3 1
a
b
c
2 9
alpha
beta
4 12
hello
world
and
codeforces
3 2
ab
c
d
3 2
abc
ab
a
1
2
2
1
0

在线编程 IDE

建议全屏模式获得最佳体验