fullmatch : 문자열이 처음부터 끝까지 패턴과 일치하는지 확인 띄어쓰기 잘못해서 공백 들어가지 않도록 조심~
import sys import re T = int(input()) p = re.compile('(100+1+|01)+') for tc in range(T): l = sys.stdin.readline().strip() if re.fullmatch(p, l): print('YES') else: print('NO')