from collections import defaultdict
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):
    newkey = []
    for key in dS:
        newkey.append((key+S[i], dS[key]))
    
    for key, c in newkey:
        dS[key] += c

for i in range(M):
    newkey = []
    for key in dT:
        newkey.append((key+T[i], dT[key]))

    for key, c in newkey:
        dT[key] += c

    

ans = 0
for key in dS:
    ans += dS[key]*dT[key]%mod

print(ans%mod)
