• + 0 comments

    for Python3 Platform

    def happyLadyBugs(b):
        for i in b:
            if i != "_" and b.count(i) == 1:
                return "NO"
                break
        
        if (b.count("_") > 0):
            return "YES"
        
        z = list(zip(b, b[1:], b[2:]))
        
        return "YES" if all(map(lambda t: t[1]==t[0] or t[1]==t[2], z)) else "NO"
    
    g = int(input())
    for i in range(g):
        n = int(input())
        b = input()
        
        result = happyLadyBugs(b)
        
        print(result)