N, M = map(int, input().split())
S_array = list(map(int, input().split()))
T_array = list(map(int, input().split()))

mod = 10**9 + 7

add_num_array = [0] * N
ans_array = [0] * (N + 1)
ans_old = [1] * (N + 1)

for t in T_array:
    ans_array = [1] * (N+1)
    for i, s in enumerate(S_array):
        if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
        ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod
    ans_old = ans_array

print(ans_array[-1]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S_array = list(map(int, input().split())) S_array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T_array = list(map(int, input().split())) T_array 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 add_num_array = [0] * N add_num_array [0] * N [0] 0 N ans_array = [0] * (N + 1) ans_array [0] * (N + 1) [0] 0 N + 1 N 1 ans_old = [1] * (N + 1) ans_old [1] * (N + 1) [1] 1 N + 1 N 1 for t in T_array:
    ans_array = [1] * (N+1)
    for i, s in enumerate(S_array):
        if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
        ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod
    ans_old = ans_array t T_array ans_array = [1] * (N+1) ans_array [1] * (N+1) [1] 1 N+1 N 1 for i, s in enumerate(S_array):
        if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
        ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod
     i s enumerate(S_array) enumerate S_array if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
         s == t s t add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod add_num_array[i] add_num_array i (add_num_array[i] + ans_old[i]) % mod add_num_array[i] + ans_old[i] add_num_array[i] add_num_array i ans_old[i] ans_old i mod ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod ans_array[i + 1] ans_array i + 1 i 1 (ans_array[i] + add_num_array[i]) % mod ans_array[i] + add_num_array[i] ans_array[i] ans_array i add_num_array[i] add_num_array i mod ans_old = ans_array ans_old ans_array print(ans_array[-1]) print ans_array[-1] ans_array -1 ans_old = ans_array ans_array ans_old mod = 10**9 + 7 10**9 + 7 mod M = map(int, input().split()) map(int, input().split()) M S_array = list(map(int, input().split())) list(map(int, input().split())) S_array ans_array = [1] * (N+1) [1] * (N+1) ans_array ans_old = [1] * (N + 1) [1] * (N + 1) ans_old N, M = map(int, input().split()) map(int, input().split()) N ans_array = [0] * (N + 1) [0] * (N + 1) ans_array T_array = list(map(int, input().split())) list(map(int, input().split())) T_array add_num_array = [0] * N [0] * N add_num_array
N, M = map(int, input().split())
S_array = list(map(int, input().split()))
T_array = list(map(int, input().split()))

mod = 10**9 + 7

add_num_array = [0] * N
ans_array = [0] * (N + 1)
ans_old = [1] * (N + 1)

for t in T_array:
    ans_array = [1] * (N+1)
    for i, s in enumerate(S_array):
        if s == t:
            add_num_array[i] = (add_num_array[i] + ans_old[i]) % mod
        ans_array[i + 1] = (ans_array[i] + add_num_array[i]) % mod
    ans_old = ans_array

print(ans_array[-1])