import re import sys content = input() pattern = r'^(\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") T = int(content) if not (1 <= T and T <= 500): sys.exit("T") for t in range(T): content = input() pattern = r'^(\d+) (\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") N, M = map(int, content.split()) if not (1 <= N and N <= 500): sys.exit("N") if not (1 <= M and M <= 500): sys.exit("M")