Help me in solving PASSWD problem

My issue

My doubt is that first and last character in U@code4CHEFINA is upper case characters, then output should be NO, because upper case characters should be inside the password, but output is given as YES, I did not understand this.

My code

# cook your dish here
t=int(input())
loweralpha="abcdefghijklmnopqrstuvwxyz"
upperalpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers="0123456789"
sc="@#%&?"

while t!=0:

    s=input()

    n=len(s)

    lac=0

    uac=0

    noc=0

    scharsc=0

    for i in s:
    
        if i in loweralpha:
            lac+=1
        
        if i in upperalpha:
            uac+=1
        
        if i in numbers:
            noc+=1
        
        if i in sc:
            scharsc+=1
        
    if (lac==0 or uac==0 or noc==0 or scharsc==0 or n<10 or s[0] not in loweralpha or s[n-1] not in loweralpha):
    
        print("NO")
    
    else:
        print("YES")
    
    t=t-1
           


Learning course: Level up from 1* to 2*
Problem Link: Practice Problem in - CodeChef