CF856B.Similar Words

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word xx is a word yy that can be obtained from xx by removing zero or more last letters of xx .

Let us call two words similar, if one of them can be obtained from the other by removing its first letter.

You are given a set SS of words. Find the maximal possible size of set of non-empty words XX such that they satisfy the following:

  • each word of XX is prefix of some word from SS ;
  • XX has no similar words.

输入格式

Input data contains multiple test cases. The first line of the input data contains an integer tt — the number of test cases. The descriptions of test cases follow.

The first line of each description contains an integer nn — the number of words in the set SS ( 1<=n<=1061<=n<=10^{6} ). Each of the following nn lines contains one non-empty word — elements of SS . All words in SS are different.

It is guaranteed that the total length of all words in one input data doesn't exceed 10610^{6} .

输出格式

For each test case print one line that contains one integer mm — the maximal number of words that XX can contain.

输入输出样例

  • 输入#1

    2
    3
    aba
    baba
    aaab
    2
    aa
    a
    

    输出#1

    6
    1
    
首页