from collections import defaultdict
import sys
from copy import copy
input = sys.stdin.readline
mod = 10**9+7
N, M = map(int, input().split())
S = "".join(input().split())
T = "".join(input().split())
dS = defaultdict(int)
dT = defaultdict(int)
dS[""] += 1
dT[""] += 1
for i in range(N):
    tmp = copy(dS)
    for key in tmp:
        dS[key+S[i]] += tmp[key]

for i in range(M):
    tmp = copy(dT)
    for key in tmp:
        dT[key+T[i]] += tmp[key]
    
ans = 0
for key in dS:
    ans += dS[key]*dT[key]%mod

print(ans%mod)
