TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description



為了破解氣球資料庫的密碼,猴子們找出了所有可能的密碼前綴候選字串 P1, P2, ..., Pm, 以及所有可能的密碼後綴候選字串 Q1, Q2, ..., Qn,已知資料庫的密碼均是來自於某個前綴候選字串的非空前綴(non-empty prefix)接上某個後綴候選字串的非空後綴(non-empty suffix)。


請你幫猴子們計算一下,總共可能有多少種不同的資料庫密碼?

Input Format

測試資料第一行有一個正整數 T (T<=200),代表測試資料組數。


對於一組測試資料而言,第一行有兩個正整數 m, n (1<=m, n<=1000)。接下來的 m+n 行,前 m 行依序是 P1, P2, ..., Pm, 後 n 行依序是 Q1, Q2, ..., Qn。所有字串都是由小寫英文字母組成,並且每一個字串長度均不超過 1000。


輸入檔的大小不超過1.5M。

Output Format

對於每一組測試資料,請輸出答案。

Sample Input 1

3
3 3
hello
world
aha
good
luck
goodluck
1 1
xyz
xyz
1 5
ha
haha
hahaha
hahahaha
hahahahaha
hahahahahaha

Sample Output 1

144
8
19

Hints

Problem Source

Migrated from old NTUJ.

UVa 12359

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200