#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
int cnt[2][311];
int n[2];
struct Node {
int child[26];
} nodes[2][100111];
int nNode[2];
int dfs(int t, int u) {
int res = 1;
REP(c,26) {
if (nodes[t][u].child[c]) {
res += dfs(t, nodes[t][u].child[c]);
if (u) ++cnt[t][c];
}
}
return res;
}
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
while (cin >> n[0] >> n[1] && n[0]) {
memset(cnt, 0, sizeof cnt);
memset(nodes, 0, sizeof nodes);
nNode[0] = nNode[1] = 1;
REP(turn,2) {
REP(i,n[turn]) {
string a; cin >> a;
if (turn == 1) reverse(a.begin(), a.end());
int p = 0;
for(char c : a) {
if (!nodes[turn][p].child[c - 'a']) {
nodes[turn][p].child[c - 'a'] = nNode[turn]++;
}
p = nodes[turn][p].child[c - 'a'];
}
}
}
long long res = 0;
res += (dfs(0, 0) - 1LL) * (dfs(1, 0) - 1LL);
REP(c,26) res -= cnt[0][c] * cnt[1][c];
cout << res << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIEZPUihpLGEsYikgZm9yKGludCBpPShhKSxfYj0oYik7IGk8PV9iOyBpKyspCiNkZWZpbmUgRk9SRChpLGEsYikgZm9yKGludCBpPShhKSxfYj0oYik7IGk+PV9iOyBpLS0pCiNkZWZpbm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zBdKSB7CiAgICAgICAgbWVtc2V0KGNudCwgMCwgc2l6ZW9mIGNudCk7CiAgICAgICAgbWVtc2V0KG5vZGVzLCAwLCBzaXplb2Ygbm9kZXMpOwoKICAgICAgICBuTm9kZVswXSA9IG5Ob2RlWzFdID0gMTsKICAgICAgICBSRVAodHVybiwyKSB7CiAgICAgICAgICAgIFJFUChpLG5bdHVybl0pIHsKICAgICAgICAgICAgICAgIHN0cmluZyBhOyBjaW4gPj4gYTsKICAgICAgICAgICAgICAgIGlmICh0dXJuID09IDEpIHJldmVyc2UoYS5iZWdpbigpLCBhLmVuZCgpKTsKCiAgICAgICAgICAgICAgICBpbnQgcCA9IDA7CiAgICAgICAgICAgICAgICBmb3IoY2hhciBjIDogYSkgewogICAgICAgICAgICAgICAgICAgIGlmICghbm9kZXNbdHVybl1bcF0uY2hpbGRbYyAtICdhJ10pIHsKICAgICAgICAgICAgICAgICAgICAgICAgbm9kZXNbdHVybl1bcF0uY2hpbGRbYyAtICdhJ10gPSBuTm9kZVt0dXJuXSsrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBwID0gbm9kZXNbdHVybl1bcF0uY2hpbGRbYyAtICdhJ107CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGxvbmcgbG9uZyByZXMgPSAwOwogICAgICAgIHJlcyArPSAoZGZzKDAsIDApIC0gMUxMKSAqIChkZnMoMSwgMCkgLSAxTEwpOwogICAgICAgIFJFUChjLDI2KSByZXMgLT0gY250WzBdW2NdICogY250WzFdW2NdOwogICAgICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQoK