#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define _for(i,a,b) for(register int i = a; i < b; ++i)
#define _rep(i,a,b) for(register int i = a; i <= b; ++i)
#define closeIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug cout << "*****************" << endl
#define FREE freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define ls l, m, rt << 1
#define rs m + 1, r, rt << 1 | 1
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
#define MAX_N 1000006
#define MAX_Tot 500005
struct Aho {
struct state {
int next[26];
int fail, cnt;
}stateTable[MAX_Tot];
int size;
queue<int> que;
void init() {
while (!que.empty()) que.pop();
for (int i = 0; i < MAX_Tot; ++i) {
memset(stateTable[i].next, 0, sizeof(stateTable[i].next));
stateTable[i].fail = stateTable[i].cnt = 0;
}
size = 1;
}
void insert(char *S) {
int n = strlen(S);
int now = 0;
for (int i = 0; i < n; ++i) {
char c = S[i];
if (!stateTable[now].next[c - 'a'])
stateTable[now].next[c - 'a'] = size++;
now = stateTable[now].next[c - 'a'];
}
stateTable[now].cnt++;
}
void build() {
stateTable[0].fail = -1;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (int i = 0; i < 26; ++i) {
if (stateTable[u].next[i]) {
if (u == 0) stateTable[stateTable[u].next[i]].fail = 0;
else {
int v = stateTable[u].fail;
while (v != -1) {
if (stateTable[v].next[i]) {
stateTable[stateTable[u].next[i]].fail = stateTable[v].next[i];
break;
}
v = stateTable[v].fail;
}
if (v == -1) stateTable[stateTable[u].next[i]].fail = 0;
}
que.push(stateTable[u].next[i]);
}
}
}
}
int Get(int u) {
int res = 0;
while (u) {
res = res + stateTable[u].cnt;
stateTable[u].cnt = 0;
u = stateTable[u].fail;
}
return res;
}
int match(char *S) {
int n = strlen(S);
int res = 0, now = 0;
for (int i = 0; i < n; ++i) {
char c = S[i];
if (stateTable[now].next[c - 'a'])
now = stateTable[now].next[c - 'a'];
else {
int p = stateTable[now].fail;
while (p != -1 && stateTable[p].next[c - 'a'] == 0) p = stateTable[p].fail;
if (p == -1) now = 0;
else now = stateTable[p].next[c - 'a'];
}
if (stateTable[now].cnt)
res = res + Get(now);
}
return res;
}
} aho;
int T, N;
char S[MAX_N];
int main() {
scanf("%d", &T);
while (T--) {
aho.init();
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%s", S);
aho.insert(S);
}
aho.build();
scanf("%s", S);
printf("%d\n", aho.match(S));
}
return 0;
}