n,q=list(map(int,input().split()));s="_"+eval(input())+"_";l,r=0,n+1

for(m,h)in[input().split()for i in range(q)][::-1]:L=h=="L";R=h=="R";l,r=[l,l-1,l+1][(m==s[l]and R)-(m==s[l+1]and L)],[r,r-1,r+1][(m==s[r-1]and R)-(m==s[r]and L)]

print((max(0,r-l-1)))
n,q=list(map(int,input().split()));s="_"+eval(input())+"_";l,r=0,n+1

for(m,h)in[input().split()for i in range(q)][::-1]:

    L=h=="L";R=h=="R";

    l+=(m==s[l+1]and L)-(m==s[l]and R)

    r+=(m==s[r]and L)-(m==s[r-1]and R)

print((max(0,r-l-1)))
n, q = list(map(int, input().split()))
s = "_" + eval(input()) + "_"
l, r = 0, n + 1
for (m, h) in [input().split() for i in range(q)][::-1]:
    L = h == "L"
    R = h == "R"
    l, r = [l, l - 1, l + 1][(m == s[l] and R) - (m == s[l + 1] and L)], [
        r,
        r - 1,
        r + 1,
    ][(m == s[r - 1] and R) - (m == s[r] and L)]
print((max(0, r - l - 1)))

n, q = list(map(int, input().split()))
s = "_" + eval(input()) + "_"
l, r = 0, n + 1
for (m, h) in [input().split() for i in range(q)][::-1]:
    L = h == "L"
    R = h == "R"
    l += (m == s[l + 1] and L) - (m == s[l] and R)
    r += (m == s[r] and L) - (m == s[r - 1] and R)
print((max(0, r - l - 1)))

-    l, r = [l, l - 1, l + 1][(m == s[l] and R) - (m == s[l + 1] and L)], [ -        r, -        r - 1, -        r + 1, -    ][(m == s[r - 1] and R) - (m == s[r] and L)] +    l += (m == s[l + 1] and L) - (m == s[l] and R) +    r += (m == s[r] and L) - (m == s[r - 1] and R)