#P3269. [JLOI2016] 字符串覆盖

[JLOI2016] 字符串覆盖

Description

String AA has NN substrings B1,B2,...,BnB_1,B_2,...,B_n. If we place each of these nn substrings at exactly one position where it occurs in AA (substrings may overlap), then some characters in AA will be covered by these NN substrings. Find the minimum and maximum possible numbers of covered characters in AA.

Input Format

The first line contains a positive integer TT, the number of test cases. It is guaranteed that T10T \le 10.

Then the TT test cases follow. For each test case:

  • The first line contains a string of lowercase letters, the main string AA.
  • The second line contains an integer NN, the number of substrings.
  • The next NN lines each contain a string of lowercase letters, describing a substring. It is guaranteed that every substring occurs in the main string.

Output Format

Output TT lines, one for each test case. Each line contains two integers MinansMinans and MaxansMaxans, the minimum and maximum numbers of characters that can be covered, respectively.

2
hello
4
he
l
l
o
abacaba
4
ab
ba
a
c
4 5 
4 6

Hint

Constraints: A10000|A| \le 10000, N4N \le 4, substring length 10000\le 10000.

Translated by ChatGPT 5