N,M=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
MOD=10**9+7
dp=[]
for i in range(len(s)+1):
  dp.append([0]*(len(t)+1))
for i in range(len(s)):
  for j in range(len(t)):
    if s[i] == t[j]: 
      dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD
    else:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]
print((dp[len(s)][len(t)]+1)%MOD) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M s=list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split t=list(map(int,input().split())) t list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split MOD=10**9+7 MOD 10**9+7 10**9 10 9 7 dp=[] dp [] for i in range(len(s)+1):
  dp.append([0]*(len(t)+1)) i range(len(s)+1) range len(s)+1 len(s) len s 1 dp.append([0]*(len(t)+1)) dp.append dp append [0]*(len(t)+1) [0] 0 len(t)+1 len(t) len t 1 for i in range(len(s)):
  for j in range(len(t)):
    if s[i] == t[j]: 
      dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD
    else:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j] i range(len(s)) range len(s) len s for j in range(len(t)):
    if s[i] == t[j]: 
      dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD
    else:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j] j range(len(t)) range len(t) len t if s[i] == t[j]: 
      dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD
    else:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j] s[i] == t[j] s[i] s i t[j] t j dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (dp[i+1][j]+dp[i][j+1]+1)%MOD dp[i+1][j]+dp[i][j+1]+1 dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 1 MOD dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i+1][j]+dp[i][j+1]-dp[i][j] dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 dp[i][j] [i] dp i j print((dp[len(s)][len(t)]+1)%MOD) print (dp[len(s)][len(t)]+1)%MOD dp[len(s)][len(t)]+1 dp[len(s)][len(t)] [len(s)] dp len(s) len s len(t) len t 1 MOD N,M=map(int,input().split()) map(int,input().split()) N t=list(map(int,input().split())) list(map(int,input().split())) t MOD=10**9+7 10**9+7 MOD dp=[] [] dp s=list(map(int,input().split())) list(map(int,input().split())) s M=map(int,input().split()) map(int,input().split()) M
N,M=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
MOD=10**9+7
dp=[]
for i in range(len(s)+1):
  dp.append([0]*(len(t)+1))
for i in range(len(s)):
  for j in range(len(t)):
    if s[i] == t[j]: 
      dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]+1)%MOD
    else:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]
print((dp[len(s)][len(t)]+1)%MOD)