package hdu;
import java.util.ArrayDeque;
import java.util.Scanner;
/**
* @description HDU 2222 Keyboards Search.
* @technique AC自动机, 字典树。
* @version 1.2
* @date 20120727
* @time 20:23
* @author Alex
*
*/
public class Hdu2222_20120727_2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i,m;
Tries root;
String str;
int cas = in.nextInt();
while(cas-->0){
root = new Tries();
m = in.nextInt();
for(i = 0; i < m; ++i){
str = in.next();
insert(root, str);
}
str = in.next();
buildAC(root);
System.out.println(query(root, str));
}
}
public static void insert(Tries root, String str){
Tries p = root;
int i, index;
for(i = 0; i < str.length(); ++i){
index = str.charAt(i) - 'a';
if(p.getNext(index) == null){
p.setNext(index);
}else{
p = p.getNext(index);
}
}
p.setCount(1);
}
public static void buildAC(Tries root){
Tries p, temp;
ArrayDeque<Tries> ad = new ArrayDeque<Tries>();
int i;
p = root;
root.setFail(null);
ad.add(root);
while(ad.size()!=0){
temp = ad.pollFirst();
p = null;
for(i = 0; i < 26; ++i){
if(temp.getNext(i)!= null){
if(temp == root){
temp.getNext(i).setFail(root);
}else{
p = temp.getFail();
while(p != null ){
if(p.getNext(i) != null){
temp.getNext(i).setFail(p.getNext(i));
break;
}else{
p = p.getFail();
}
}
if(p == null){
temp.getNext(i).setFail(root);
}
}
ad.add(temp.getNext(i));
}
}
}
}
private static int query(Tries root, String str){
int i, cnt = 0, index, len = str.length();
Tries p = root, temp;
for(i = 0; i < len; ++i){
index = str.charAt(i) - 'a';
while(p != root&&p.getNext(index) == null ){
p = p.getFail();
if(p==null){
p = root;
}
}
p = p.getNext(index);
if(p==null){
p = root;
}
temp = p;
while(temp!= root && temp.getCount()!=-1){
cnt += temp.getCount();
temp.setCount(-1);
temp = temp.getFail();
System.out.println(temp);
System.out.println(root);
}
}
return cnt;
}
}
class Tries{
int count;
private Tries fail;
private Tries[] next;
public Tries(){
count = 0;
fail = null;
next = new Tries[26];
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Tries getFail() {
return fail;
}
public void setFail(Tries fail) {
this.fail = fail;
}
public Tries getNext(int index){
return this.next[index];
}
public void setNext(int index){
this.next[index] = new Tries();
}
public Tries[] getNext() {
return next;
}
public void setNext(Tries[] next) {
this.next = next;
}
}