N=int(eval(input()))

S=eval(input())

l,r=[0]*N,[0]*N

for i in range(N-1):

    l[i+1]+=l[i]+(S[i]=='W')

for i in range(N-1,0,-1):

    r[i-1]+=r[i]+(S[i]=='E')

ans=r[i]

for i in range(1,N):

    ans=min(ans,l[i]+r[i])

print(ans)

N=int(eval(input()))

S=eval(input())

ans=cur=S.count('W')

for c in reversed(S):

    if c=='W':

        cur-=1

    else:

        cur+=1

    ans=min(ans,cur)

print(ans)

N = int(eval(input()))
S = eval(input())
l, r = [0] * N, [0] * N
for i in range(N - 1):
    l[i + 1] += l[i] + (S[i] == "W")
for i in range(N - 1, 0, -1):
    r[i - 1] += r[i] + (S[i] == "E")
ans = r[i]
for i in range(1, N):
    ans = min(ans, l[i] + r[i])
print(ans)

N = int(eval(input()))
S = eval(input())
ans = cur = S.count("W")
for c in reversed(S):
    if c == "W":
        cur -= 1
    else:
        cur += 1
    ans = min(ans, cur)
print(ans)

-l, r = [0] * N, [0] * N -for i in range(N - 1): -    l[i + 1] += l[i] + (S[i] == "W") -for i in range(N - 1, 0, -1): -    r[i - 1] += r[i] + (S[i] == "E") -ans = r[i] -for i in range(1, N): -    ans = min(ans, l[i] + r[i]) +ans = cur = S.count("W") +for c in reversed(S): +    if c == "W": +        cur -= 1 +    else: +        cur += 1 +    ans = min(ans, cur)