import random

testNum = 0

def printTest(s):
	global testNum
	testNum += 1
	print("[%02d]"%testNum)
	fout = open("%02d"%testNum, "w")
	fout.write("%d %d\n"%(len(s), len(s[0])))
	for e in s:
		fout.write(e + "\n")
	fout.close()

def genChess(n, m):
	s = []
	color = random.randint(0, 1)
	for i in range(n):
		e = ""
		for j in range(m):
			e += "WB"[((i ^ j ^ color) & 1)]
		s.append(e)
	printTest(s)

def genRandom(n, m):
	s = []
	color = random.randint(0, 1)
	for i in range(n):
		e = ""
		for j in range(m):
			e += "WB"[random.randint(0, 1)]
		s.append(e)
	printTest(s)

def genSmall(n, m, changes):
	s = []
	color = random.randint(0, 1)
	for i in range(n):
		e = []
		for j in range(m):
			e.append("WB"[((i ^ j ^ color) & 1)])
		s.append(e)
	for c in range(changes):
		t = random.randint(0, 1)
		if t == 0:
			diff = random.randint(-m + 1, n - 1)
			h = random.randint(1, min(n, m))
			for z in range(h):
				x = random.randint(0, n - 1)
				y = x - diff
				if not (y in range(0, m)):
					continue
				s[x][y] = 'W' if s[x][y] == 'B' else 'B'
		else:
			sum = random.randint(0, n + m - 2)
			h = random.randint(1, min(n, m))
			for z in range(h):
				x = random.randint(0, n - 1)
				y = sum - x
				if not (y in range(0, m)):
					continue
				s[x][y] = 'W' if s[x][y] == 'B' else 'B'
	d = []
	for e in s:
		q = ""
		for j in e:
			q += j
		d.append(q)
	printTest(d)

printTest(["WBB", "BWB", "BBW"])
printTest(["WBW", "WWB", "WWW"])
printTest(["WWW"])
printTest(["W"])
printTest(["B"])
genChess(100, 100)
genRandom(100, 100)
genSmall(100, 100, 20)
genChess(1, random.randint(2, 100))
genChess(random.randint(2, 100), 1)
genRandom(1, random.randint(2, 100))
genRandom(random.randint(2, 100), 1)
genChess(6, 8)                                                                                             
genChess(99, 55)
for i in range(10):
	genRandom(random.randint(2, 100), random.randint(2, 100))
genRandom(50, 50)
genRandom(88, 88)
for i in range(14):
	genSmall(random.randint(2, 100), random.randint(2, 100), random.randint(8, 20))
for i in range(10):
	genSmall(random.randint(2, 100), random.randint(2, 100), random.randint(1, 4))