n=int(eval(input()))

s=eval(input())

p=s[1:].count("E")

ans=p

for i in range(1,n):

    if s[i]=="E":p -=1

    if s[i-1]=="W":p +=1

    ans=min(ans,p)

print(ans)
n=int(eval(input()))

s=eval(input())

num=s.count("E")

length=len(s)



ans=num

for i in range(length):

    if s[i]=="W":num +=1

    elif s[i]=="E":num -=1

    ans=min(ans,num)



print(ans)
n = int(eval(input()))
s = eval(input())
p = s[1:].count("E")
ans = p
for i in range(1, n):
    if s[i] == "E":
        p -= 1
    if s[i - 1] == "W":
        p += 1
    ans = min(ans, p)
print(ans)

n = int(eval(input()))
s = eval(input())
num = s.count("E")
length = len(s)
ans = num
for i in range(length):
    if s[i] == "W":
        num += 1
    elif s[i] == "E":
        num -= 1
    ans = min(ans, num)
print(ans)

-p = s[1:].count("E") -ans = p -for i in range(1, n): -    if s[i] == "E": -        p -= 1 -    if s[i - 1] == "W": -        p += 1 -    ans = min(ans, p) +num = s.count("E") +length = len(s) +ans = num +for i in range(length): +    if s[i] == "W": +        num += 1 +    elif s[i] == "E": +        num -= 1 +    ans = min(ans, num)