A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.

As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.

Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.

It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.

Input

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.

It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.

Examples

Input

WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW


Output

3


Input

WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW


Output

1

Difficulty: EASY
Tags: Complete search

Constructive algorithms
Skill types: Complete search

Starter code:

Solutions:
e = 0
s1 = ''
s2 = ''
s3 = ''
s4 = ''
s5 = ''
s6 = ''
s7 = ''
s8 = ''
for i in range(8):
	s = str(input())
	if s == 'B' * 8:
		e = e + 1
	s1 = s1 + s[0]
	s2 = s2 + s[1]
	s3 = s3 + s[2]
	s4 = s4 + s[3]
	s5 = s5 + s[4]
	s6 = s6 + s[5]
	s7 = s7 + s[6]
	s8 = s8 + s[7]
if s1 == 'B' * 8:
	e = e + 1
if s2 == 'B' * 8:
	e = e + 1
if s3 == 'B' * 8:
	e = e + 1
if s4 == 'B' * 8:
	e = e + 1
if s5 == 'B' * 8:
	e = e + 1
if s6 == 'B' * 8:
	e = e + 1
if s7 == 'B' * 8:
	e = e + 1
if s8 == 'B' * 8:
	e = e + 1
if e == 16:
	print(8)
else:
	print(e)


m = 0
t = 0
for i in range(8):
	n = input()
	if n == 'BBBBBBBB':
		m += 1
	elif t == 0:
		t = 1
		m += n.count('B')
	else:
		pass
print(m)


def count():
	M = []
	for i in range(8):
		x = input()
		M.append(x)
	c = 0
	mark = []
	for i in range(len(M)):
		if M[i] == 'B' * 8:
			c += 1
			mark.append(i)
	for i in range(8):
		if i not in mark:
			for j in M[i]:
				if j == 'B':
					c += 1
			break
	print(c)
count()


n = 0
m = 0
k = 0
for _ in range(8):
	s = input()
	if s == 'BBBBBBBB':
		n += 1
	else:
		for i in s:
			if i == 'B':
				m += 1
		k += 1
if k == 0:
	ans = 8
else:
	ans = n + m // k
print(ans)


matrix = []
for i in range(8):
	line = input()
	matrix.append(line)
total_count = 0
t = 0
for i in range(8):
	row_count = 0
	for j in range(8):
		if matrix[i][j] == 'B':
			row_count += 1
	if row_count != 8:
		total_count = row_count
		t = 1
		break
if t == 0:
	print(8)
else:
	for col in range(8):
		col_count = 0
		for row in range(8):
			if matrix[row][col] == 'B':
				col_count += 1
		if col_count != 8:
			total_count += col_count
			break
	print(total_count)


import sys
lines = list(sys.stdin.read().strip().split())
print_lines = 0
columns = [0 for _ in range(8)]
for line in lines:
	if line == 'BBBBBBBB':
		print_lines += 1
	for (j, s) in enumerate(line):
		columns[j] += bool(s == 'B')
print_col = sum((j == 8 for j in columns))
if print_col == 8:
	print_col = 0
print(print_lines + print_col)


import math
have = [['W' for i in range(8)] for x in range(8)]

def paintcol(x):
	for row in range(8):
		have[row][x] = 'B'

def paintrow(x):
	for col in range(8):
		have[x][col] = 'B'
want = list()
for i in range(8):
	want.append(list(input()))
res = 0
for row in range(8):
	count = 0
	for col in range(8):
		if want[row][col] == 'B':
			count += 1
	if count == 8:
		res += 1
		paintrow(row)
for col in range(8):
	good = True
	for row in range(8):
		if want[row][col] != have[row][col]:
			good = False
	if not good:
		res += 1
		paintcol(col)
print(res)


__author__ = 'Darren'

def solve():
	board = [input() for i in range(8)]
	column_counted = False
	count = 0
	for line in board:
		if line == 'BBBBBBBB':
			count += 1
		elif not column_counted:
			count += line.count('B')
			column_counted = True
		else:
			pass
	print(count)
solve()


s1 = []
s2 = ['' for i in range(8)]
for i in range(8):
	s = input()
	s1.append(s)
	for j in range(8):
		s2[j] += s[j]
k1 = s1.count('BBBBBBBB')
k2 = s2.count('BBBBBBBB')
if k1 == 8:
	print(k1)
else:
	print(k1 + k2)


(l, l2, count) = ([], [], 0)
(b, w) = ('BBBBBBBB', 'WWWWWWWW')
for _ in range(8):
	l.append(input())
for i in range(8):
	if l[i] == b:
		count += 1
		l[i] = w
for i in range(8):
	c = [x[i] for x in l]
	l2.append(c)
for col in l2:
	if 'B' in col:
		count += 1
print(count)


import math

def getNrOfPaintedLines():
	inputList = []
	paintedLines = 0
	for i in range(8):
		line = input()
		inputList.append(list(line))
	for row in inputList:
		onlyB = True
		for char in row:
			if char != 'B':
				onlyB = False
		if onlyB:
			paintedLines += 1
	if paintedLines == 8:
		print(paintedLines)
		return
	for column in range(8):
		onlyB = True
		for row in range(8):
			if inputList[row][column] != 'B':
				onlyB = False
		if onlyB:
			paintedLines += 1
	print(paintedLines)
getNrOfPaintedLines()


n = []
count = 0
for i in range(8):
	n.append(input())
count = n.count('BBBBBBBB')
for i in range(0, 8):
	lis = []
	for j in range(8):
		if n[j][i] == 'W':
			break
		else:
			lis.append(n[j][i])
	if len(lis) == 8:
		count += 1
if count != 16:
	print(count)
else:
	print(8)


ans = 0
metColumn = False
for i in range(8):
	s = input()
	if s == 'BBBBBBBB':
		ans += 1
	elif not metColumn:
		ans += s.count('B')
		metColumn = True
print(ans)


l = []
m = []
a = ''
for j in range(0, 8):
	a = input()
	m.append(a)
	a = ''
pr = 0
tot = 0
for i in range(0, 8):
	if m[i].count('B') == 8:
		tot += 1
for i in range(0, 8):
	for j in range(0, 8):
		if m[j][i] == 'B':
			pr += 1
	if pr == 8:
		tot += 1
	pr = 0
if tot == 16:
	print(8)
else:
	print(tot)


l = []
count = 0
for i in range(8):
	l.append(input())
for i in range(8):
	b = []
	if l[i] == 'BBBBBBBB':
		count += 1
	for j in range(8):
		if l[j][i] == 'W':
			break
		else:
			b.append(l[j][i])
	if len(b) == 8:
		count += 1
if count == 16:
	print(8)
else:
	print(count)


def judge(i, flag):
	global a
	paint = 1
	if flag == 0:
		for j in range(8):
			if a[i][j] == 'W':
				paint = 0
				break
	else:
		for j in range(8):
			if a[j][i] == 'W':
				paint = 0
				break
	return paint
a = []
ans = 0
for i in range(8):
	r = list(input())
	a.append(r)
for i in range(8):
	ans += judge(i, 0)
for i in range(8):
	ans += judge(i, 1)
if ans == 16:
	print(8)
else:
	print(ans)


mins = int(1000000000.0)
nu8 = 0
for i in range(8):
	A = input()
	dem = 0
	for j in range(8):
		if A[j] == 'B':
			dem += 1
	if dem < mins:
		mins = dem
	if dem == 8:
		nu8 += 1
print(nu8 + mins % 8)


S = []
for i in range(8):
	s = input()
	S.append(s)
satr_B = 0
ustun_B = 0
for i in range(8):
	if S[i].count('B') == 8:
		satr_B += 1
if satr_B == 8:
	print(8)
else:
	for i in range(8):
		t = True
		for j in range(8):
			if S[j][i] == 'W':
				t = False
				break
		if t:
			ustun_B += 1
	print(ustun_B + satr_B)


a = list((0 for i in range(8)))
o = 0
for i in range(8):
	(s, c) = (input(), 0)
	for j in range(8):
		if s[j] == 'B':
			a[j] += 1
			c += 1
	if c == 8:
		o += 1
if o == 8:
	print(8)
	quit()
print(o + a.count(8))


gl = [input() for i in range(8)]
cnt = 0
for i in range(8):
	if gl[i][0] == gl[i][1] == gl[i][2] == gl[i][3] == gl[i][4] == gl[i][5] == gl[i][6] == gl[i][7] == 'B':
		cnt += 1
	if gl[0][i] == gl[1][i] == gl[2][i] == gl[3][i] == gl[4][i] == gl[5][i] == gl[6][i] == gl[7][i] == 'B':
		cnt += 1
if cnt == 16:
	cnt = 8
print(cnt)


a = []
for _ in range(8):
	a.append(input())
x = 0
for i in a:
	if i == 'BBBBBBBB':
		x += 1
if x == 8:
	print(8)
	exit()
for i in range(8):
	q = True
	for j in range(8):
		if a[j][i] == 'W':
			q = False
	if q:
		x += 1
print(x)


def main():
	goal = tuple((input().count('B') for _ in range(8)))
	least = min(goal)
	if least == 8:
		print(8)
	else:
		print(least + goal.count(8))
main()


a = [input() for i in range(8)]
b = [''.join((j[i] for j in a)) for i in range(8)]
s = a.count('B' * 8) + b.count('B' * 8)
print(s if s != 16 else 8)


l = []
for _ in range(8):
	l.append(input().count('B'))
print(min(l) % 8 + l.count(8))


matrix = list()
result = 0
for x in range(8):
	matrix.append(input())
	if matrix[x].count('B') == 8:
		result += 1
if result < 8:
	for x in range(8):
		count = 0
		for y in range(8):
			if matrix[y][x] == 'B':
				count += 1
		if count == 8:
			result += 1
print(result)


n = 8
s = []
for i in range(n):
	c = list(input())
	s.append(c)
answer = 0
for i in range(8):
	count = 0
	for j in range(8):
		if s[i][j] == 'B':
			count = count + 1
	if count == 8:
		answer = answer + 1
if answer == 8:
	print(answer)
else:
	for i in range(8):
		count = 0
		for j in range(8):
			if s[j][i] == 'B':
				count = count + 1
		if count == 8:
			answer = answer + 1
	print(answer)


a = [[x == 'B' for x in input()] for _ in range(8)]
h = [False] * 8
for i in range(8):
	h[i] = all(a[i])
v = [False] * 8
for i in range(8):
	v[i] = all((x[i] for x in a))
s = sum(h) + sum(v)
print(s if s < 16 else 8)


a = []
verts = [0] * 8
hors = [0] * 8
for i in range(8):
	a.append(input())
	hors[i] = sum((x == 'B' for x in a[-1]))
for i in range(8):
	verts[i] = sum((x[i] == 'B' for x in a))
if hors == [8] * 8 and verts == [8] * 8:
	print(8)
else:
	print(sum((x == 8 for x in verts)) + sum((x == 8 for x in hors)))


a = []
r = 0
for k in range(8):
	a.append(input())
for i in a:
	m = 0
	for k in range(len(i)):
		m += ord(i[k])
	if m == 528:
		r += 1
if r == 8:
	print(r)
	exit()
for k in range(8):
	m = 0
	for i in range(len(a)):
		m += ord(a[i][k])
	if m == 528:
		r += 1
print(r)


order = []
for i in range(8):
	order.append(input())
allBlack = True
count = 0
for row in order:
	if row == 'BBBBBBBB':
		count += 1
	else:
		allBlack = False
for i in range(8):
	count += 1
	for ii in range(8):
		if order[ii][i] == 'W':
			count -= 1
			break
if count == 16:
	print('8')
else:
	print(count)


rows = []
count = 0
for _ in range(8):
	rows.append(input())
	if rows[-1] == 'B' * 8:
		count += 1
if count == 8:
	print(8)
else:
	for i in range(8):
		if [rows[j][i] for j in range(8)] == ['B'] * 8:
			count += 1
	print(count)


m = 0
rows = []
columns = []
c1 = ''
c2 = ''
c3 = ''
c4 = ''
c5 = ''
c6 = ''
c7 = ''
c8 = ''
for i in range(8):
	row = input()
	rows.append(row)
	c1 = c1 + row[0]
	c2 = c2 + row[1]
	c3 = c3 + row[2]
	c4 = c4 + row[3]
	c5 = c5 + row[4]
	c6 = c6 + row[5]
	c7 = c7 + row[6]
	c8 = c8 + row[7]
columns = [c1, c2, c3, c4, c5, c6, c7, c8]
for row in rows:
	if row.count('B') == 8:
		m = m + 1
for column in columns:
	if column.count('B') == 8:
		m = m + 1
if m == 16:
	m = 8
print(m)


b = [['B' for j in range(8)] for i in range(8)]
wb = [[x for x in input()] for i in range(8)]
s = 0
for i in range(8):
	if b[i] == wb[i]:
		s += 1
if s != 8:
	for i in range(8):
		r = 0
		for j in range(8):
			if b[j][i] == wb[j][i]:
				r += 1
		if r == 8:
			s += 1
print(s)


s1 = set([_ for _ in range(8)])
s2 = set([_ for _ in range(8)])
for i in range(8):
	line = input()
	for j in range(8):
		if line[j] == 'W':
			s1.discard(i)
			s2.discard(j)
ans = len(s1) + len(s2)
print(ans if not ans == 16 else 8)


def main():
	(field, res) = ([c == 'B' for _ in range(8) for c in input()], 0)
	for i in range(0, 64, 8):
		if all(field[i:i + 8]):
			field[i:i + 8] = [False] * 8
			res += 1
	for i in range(8):
		if any(field[i::8]):
			field[i::8] = [False] * 8
			res += 1
	print(res)
main()


k = 0
a = []
for i in range(8):
	b = list(input())
	c = b.count('B')
	if c == 8:
		k += 1
	a.append(b)
for i in range(len(a)):
	c = a[i].count('B')
	if c != 8:
		k += c
		break
print(k)


import sys

def main():
	chessboard = [line.strip() for line in sys.stdin.readlines()]
	count = len([row for row in chessboard if row == 'B' * 8])
	if count < 8:
		count += len([column for column in (''.join(c) for c in zip(*chessboard)) if column == 'B' * 8])
	sys.stdout.write(str(count) + '\n')
main()


set1 = []
counter = 0
for i in range(8):
	s = input()
	set1.append(s)
for i in range(8):
	if set1[i] == 'BBBBBBBB':
		counter += 1
if counter == 8:
	print(counter)
else:
	set2 = [[row[i] for row in set1] for i in range(len(set1))]
	for i in range(8):
		s = ''.join(set2[i])
		set1[i] = s
	for i in range(8):
		if set1[i] == 'BBBBBBBB':
			counter += 1
	print(counter)


x = [list(input()).count('B') for i in range(8)]
print(min(x) % 8 + x.count(8))


a = [input() for i in range(8)]
was = [[0] * 8 for i in range(8)]
cnt = 0
for i in range(8):
	if a[i] == 'B' * 8 and sum(was[i]) < 8:
		was[i] = [1] * 8
		cnt += 1
for i in range(8):
	if [a[j][i] for j in range(8)] == ['B'] * 8 and sum((was[j][i] for j in range(8))) < 8:
		for j in range(8):
			was[j][i] = 1
		cnt += 1
print(cnt)


a = [input().count('B') for i in range(8)]
print(min(a) % 8 + a.count(8))


ans = 0
a = []
for u in range(8):
	a.append(input())
for u in range(8):
	if a[u] == 'BBBBBBBB':
		ans += 1
		a[u] = 'WWWWWWWW'
for u in range(8):
	if a[0][u] == 'B' or a[1][u] == 'B' or a[2][u] == 'B' or (a[3][u] == 'B') or (a[4][u] == 'B') or (a[5][u] == 'B') or (a[6][u] == 'B') or (a[7][u] == 'B'):
		ans += 1
print(ans)


import cmath
d = {}
c = 0
ans = 0
for i in range(1, 9):
	x = list('0' + input())
	if 'W' in x:
		c = 1
	else:
		ans = ans + 1
	for j in range(1, 9):
		z = complex(i, j)
		d[z] = x[j]
if c == 0:
	exit(print('8'))
for i in range(1, 9):
	w = 0
	for j in range(1, 9):
		if d[complex(j, i)] == 'B':
			w = w + 1
	if 8 == w:
		ans = ans + 1
print(ans)


(row, col) = (0, 0)
for i in range(8):
	s = input()
	ans = 0
	for it in s:
		if it == 'B':
			ans += 1
	if ans == 8:
		row += 1
	else:
		col = ans
print(row + col)


l = []
for i in range(8):
	l.append(input())
c = 0
for i in range(8):
	for j in range(8):
		if l[i][j] == 'W':
			c += 1
			break
for i in range(8):
	for j in range(8):
		if l[j][i] == 'W':
			c += 1
			break
if c == 0:
	print(8)
else:
	print(16 - c)


t = [input().count('B') for i in range(8)]
print(t.count(8) + min(t) % 8)


count = 0
columns = ['', '', '', '', '', '', '', '']
for _ in range(8):
	line = input()
	if 'W' not in line:
		count += 1
	for (index, character) in enumerate(line):
		columns[index] += character
for column in columns:
	if 'W' not in column:
		count += 1
print(8 if count == 16 else count)


c = 0
f = 0
for i in range(8):
	a = input()
	if f == 0 and a.count('B') < 8:
		c += a.count('B')
		f = 1
	elif a.count('W') == 0:
		c += 1
print(c)


board = []
rowVals = [1] * 8
colVals = [1] * 8
for row in range(0, 8):
	line = input().strip()
	col = 0
	for char in line:
		if char == 'W':
			rowVals[row] = 0
			colVals[col] = 0
		col += 1
total = 0
for row in rowVals:
	if row == 1:
		total += 1
for col in colVals:
	if col == 1:
		total += 1
if total == 16:
	print(8)
else:
	print(total)


grid = [input() for _ in range(8)]
result = grid.count('B' * 8)
grid = '\n'.join((''.join((grid[i][j] for i in range(8))) for j in range(8)))
result += grid.count('B' * 8)
result = 8 if result == 16 else result
print(result)


chessBoard = []
for i in range(8):
	chessBoard.append(list(input()))
blackTileCount = 0
for i in range(8):
	blackTileCount += chessBoard[i].count('B')

def extractColumn(j):
	colString = ''
	for x in range(8):
		colString += chessBoard[x][j]
	return colString
paintedCount = 0
for i in range(8):
	rowString = ''.join(chessBoard[i])
	if rowString == 'BBBBBBBB':
		paintedCount += 1
if 8 * paintedCount == blackTileCount:
	print(paintedCount)
	exit()
for i in range(8):
	colString = extractColumn(i)
	if colString == 'BBBBBBBB':
		paintedCount += 1
print(paintedCount)


def isFull():
	for i in rows:
		if i != 'BBBBBBBB':
			return False
	return True
rows = []
for i in range(8):
	rows.append(input())
if isFull():
	print(8)
	exit(0)
columns = []
for i in range(8):
	s = ''
	for c in rows:
		s += c[i]
	columns.append(s)
strokes = 0
for i in rows:
	if i == 'BBBBBBBB':
		strokes += 1
for i in columns:
	if i == 'BBBBBBBB':
		strokes += 1
print(strokes)


def readln():
	return tuple(map(int, input().split()))
b = [list(input()) for _ in range(8)]
cnt1 = sum([1 for s in b if s == ['B'] * 8])
cnt2 = sum([1 for s in zip(*b) if list(s) == ['B'] * 8])
print(8 if cnt1 == 8 else cnt1 + cnt2)


a = []
for i in range(8):
	s = input()
	a.append(s)
k = 0
p = 0
for i in range(8):
	s = a[i]
	if s[0] == 'B':
		t = True
		for j in range(8):
			if s[j] != 'B':
				t = False
		if t:
			k += 1
s = a[0]
for i in range(8):
	if s[i] == 'B':
		t = True
		for j in range(8):
			if a[j][i] != 'B':
				t = False
		if t:
			p += 1
if k == 8 and p == 8:
	print(8)
else:
	print(k + p)


a = b = 0
for i in range(8):
	x = input()
	c = x.count('B')
	if c == 8:
		a += 1
	elif c < 8:
		b = c
print(a + b)


l = [[], [], [], [], [], [], [], [], []]
c = 0
for i in range(8):
	k = input()
	if len(set(k)) == 1 and 'B' in k:
		c += 1
	for i in range(8):
		l[i].append(k[i])
if c < 8:
	for e in l:
		if len(set(e)) == 1 and 'B' in e:
			c += 1
print(c)


a = []
c = 0
for i in range(8):
	x = list(input())
	if x.count('B') == 8:
		c += 1
	a.append(x)
if c == 8:
	print(8)
	exit()
for i in zip(*a):
	if i.count('B') == 8:
		c += 1
print(c)


l = []
for x in range(8):
	l.append(input().strip())
count = 0
for x in range(8):
	done = False
	for y in range(8):
		if l[x][y] == 'W':
			done = True
	if not done:
		count += 1
if count == 8:
	print(count)
else:
	count1 = 0
	for x in range(8):
		done = False
		for y in range(8):
			if l[y][x] == 'W':
				done = True
		if not done:
			count1 += 1
	print(count + count1)


a = []
t = 0
q = ['B'] * 8
for i in range(8):
	b = list(input())
	if b == q:
		t += 1
	a.append(b[:])
for i in range(8):
	r = []
	for j in range(8):
		r.append(a[j][i])
	if r == q:
		t += 1
if t == 16:
	print(8)
else:
	print(t)


import sys
m = []

def is_row(x):
	for i in range(8):
		if m[i][x] != 'B':
			return False
	return True

def is_col(x):
	for i in range(8):
		if m[x][i] != 'B':
			return False
	return True
for i in range(8):
	m.append(list(sys.stdin.readline().strip()))
result = 0
for i in range(8):
	if is_row(i):
		result += 1
	if is_col(i):
		result += 1
if result == 16:
	result //= 2
print(result)


s = [input().count('B') for i in range(8)]
print(min(s) % 8 + s.count(8))


chessboard = [list(input()) for i in range(8)]
line_num = 0
for i in range(8):
	tmp = True
	for j in range(8):
		if chessboard[i][j] == 'W':
			tmp = False
			break
	if tmp:
		line_num += 1
	tmp = True
	for j in range(8):
		if chessboard[j][i] == 'W':
			tmp = False
			break
	if tmp:
		line_num += 1
if line_num == 16:
	print(8)
else:
	print(line_num)


(requirement, board, count) = ([], [], 0)
for i in range(8):
	requirement.append(list(input()))
	board.append(['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W'])
for i in range(8):
	for j in range(8):
		if requirement[i][j] == 'W':
			break
	else:
		for k in range(8):
			board[i][k] = 'B'
		count += 1
	if board == requirement:
		print(count)
		break
if board != requirement:
	for i in range(8):
		for j in range(8):
			if requirement[j][i] == 'W':
				break
		else:
			for k in range(8):
				board[k][i] = 'B'
			count += 1
		if board == requirement:
			print(count)
			break


row = 0
col = 0
l = []
for i in range(8):
	l.append(input())
	if l[i] == 'BBBBBBBB':
		row += 1
if row == 8:
	print(8)
else:
	for i in range(8):
		if ''.join([x[i] for x in l]) == 'BBBBBBBB':
			col += 1
	print(col + row)


a = 0
b = 0
for _ in range(8):
	n = input().count('B')
	if n < 8:
		b = n
	else:
		a += 1
print(a + b)


cb = [list(input()) for _ in range(8)]
count = 0
for i in range(8):
	for j in range(8):
		if cb[i][j] != 'B':
			break
	else:
		count += 1
	for j in range(8):
		if cb[j][i] != 'B':
			break
	else:
		count += 1
if count == 16:
	print(8)
else:
	print(count)


board = []
count = 0
for _ in range(8):
	board.append(input())
for i in range(8):
	if board[i] == 'BBBBBBBB':
		count += 1
	incount = 0
	for j in range(8):
		if board[j][i] == 'B':
			incount += 1
		if incount == 8:
			count += 1
if count == 16:
	print(8)
else:
	print(count)


d = 0
c = 0
for i in range(0, 8):
	a = input()
	if a != 'BBBBBBBB' and d == 0:
		d = 1
		for j in range(0, 8):
			if a[j] == 'B':
				c += 1
	if a == 'BBBBBBBB':
		c += 1
print(c)


l1 = input()
l2 = input()
l3 = input()
l4 = input()
l5 = input()
l6 = input()
l7 = input()
l8 = input()
d = []
c = 0
if l1.count('B') == 8:
	c += 1
else:
	d += [l1.count('B')]
if l2.count('B') == 8:
	c += 1
else:
	d += [l2.count('B')]
if l3.count('B') == 8:
	c += 1
else:
	d += [l3.count('B')]
if l4.count('B') == 8:
	c += 1
else:
	d += [l4.count('B')]
if l5.count('B') == 8:
	c += 1
else:
	d += [l5.count('B')]
if l6.count('B') == 8:
	c += 1
else:
	d += [l6.count('B')]
if l7.count('B') == 8:
	c += 1
else:
	d += [l7.count('B')]
if l8.count('B') == 8:
	c += 1
else:
	d += [l8.count('B')]
r = 0
if len(d) >= 1:
	r = max(d)
print(c + r)


list1 = []
count = 0
for i in range(8):
	row_list = list(input())
	add = 1
	for j in range(8):
		if row_list[j] == 'W':
			add = 0
			break
	count += add
	list1.append(row_list)
for x in range(8):
	add = 1
	for y in range(8):
		if list1[y][x] == 'W':
			add = 0
			break
	count += add
if count == 16:
	count = 8
print(count)


count = 0
co = 0
c = 0
for i in range(0, 8):
	p = input()
	if len(set(p)) == 1 and p[0] == 'B':
		count = count + 1
	if len(set(p)) == 1 and p[0] != 'B':
		co = co + 1
	else:
		for j in range(0, 8):
			if p[j] == 'B':
				c = c + 1
if count != 8:
	c = (c - 8 * count) / (8 - count)
	print(int(c + count))
if count == 8:
	print('8')


from sys import stdin
s_arr = []
while True:
	s = stdin.readline().strip()
	if len(s) <= 1:
		break
	s_arr.append(s)
check = 'BBBBBBBB'
count = 0
for i in s_arr:
	if check == i:
		count += 1
for i in range(len(s_arr[0])):
	check2 = ''
	for j in range(len(s_arr[0])):
		check2 = check2 + s_arr[j][i]
	if check == check2:
		count += 1
if count == 16:
	count = count // 2
print(count)


a = []
r = 0
for k in range(8):
	a.append(input())
for i in range(8):
	if str(a[0][i]) == str(a[1][i]) == str(a[2][i]) == str(a[3][i]) == str(a[4][i]) == str(a[5][i]) == str(a[6][i]) == str(a[7][i]) == 'B':
		r += 1
if r == 8:
	print(8)
	exit()
for i in range(8):
	if str(a[i][0]) == str(a[i][1]) == str(a[i][2]) == str(a[i][3]) == str(a[i][4]) == str(a[i][5]) == str(a[i][6]) == str(a[i][7]) == 'B':
		r += 1
print(r)


def row(n):
	j = 0
	for i in range(8):
		if 'W' not in n[i]:
			j += 1
	return j

def col(n):
	h = 0
	for j in range(8):
		for i in range(8):
			if n[i][j] == 'W':
				break
			elif n[i][j] == 'B' and i == 7:
				h += 1
	return h

def main():
	c = []
	for i in range(8):
		c += [[]]
		c[i] += input()
	a = row(c) + col(c)
	if a == 16:
		print(8)
	else:
		print(a)
main()


a = True
c = 0
for i in range(8):
	x = input()
	if 'W' not in x:
		c += 1
	elif a:
		for i in x:
			if i == 'B':
				c += 1
		a = False
print(c)


a = []
ans = 0
for i in range(8):
	temp = input()
	a.append(temp)
	if temp == 'BBBBBBBB':
		ans += 1
if ans < 8:
	for i in range(8):
		x = 0
		for j in range(8):
			if a[j][i] == 'B':
				x += 1
			else:
				break
		if x == 8:
			ans += 1
print(ans)


board = []
strokes = 0
checked = False
for i in range(8):
	row = list(input())
	board.append(row)
for r in board:
	count = 0
	for c in r:
		if c == 'B':
			count += 1
	if count == 8:
		strokes += 1
	elif count > 0 and (not checked):
		checked = True
		strokes += count
print(strokes)


a = []
c = 0
for i in range(8):
	a.append(input())
	if a[i] == 'B' * 8:
		c += 1
		a[i] = 'A' * 8
for j in range(8):
	d = 0
	for i in range(8):
		if a[i][j] == 'W':
			d = 0
			break
		elif a[i][j] == 'B':
			d = 1
	c += d
print(c)


chess_board = []
n = 8
count = 0
diagonal = ''
count_B = 0
while n:
	chess_board.append(input())
	diagonal += chess_board[-1][8 - n]
	count_B += chess_board[-1].count('B')
	n -= 1
if diagonal == 'BBBBBBBB' and count_B == 64:
	count = 8
else:
	for i in range(8):
		if diagonal[i] == 'B':
			if chess_board[i] == 'BBBBBBBB':
				count += 1
			painted = 1
			for j in range(8):
				if chess_board[j][i] != 'B':
					painted = 0
					break
			if painted:
				count += 1
print(count)


count = 0
column = [0, 0, 0, 0, 0, 0, 0, 0]
i = 0
for x in range(8):
	linha = input()
	verify = 0
	for c in linha:
		if c == 'B':
			verify += 1
	if verify == 8:
		count = count + 1
	elif verify < 8:
		i = verify
print(count + i)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	grid = []
	ans = 0
	for i in range(8):
		grid.append(insr())
		if grid[i] == 'BBBBBBBB':
			ans += 1
			grid[i] = 'XXXXXXXX'
	for i in range(8):
		for j in range(8):
			cnt = 0
			if grid[j][i] == 'B':
				ans += 1
				break
	print(ans)


l = []
x = y = n = 0
for _ in range(8):
	s = input()
	if s == 'BBBBBBBB':
		x += 1
	elif 'B' in s:
		y += s.count('B')
if x != 8:
	print(x + y // (8 - x))
else:
	print(x)


(s, p) = ([], [''] * 8)
for i in range(8):
	s.append(input())
	for j in range(8):
		p[j] += s[i][j]
print(8 if s.count('BBBBBBBB') == 8 else s.count('BBBBBBBB') + p.count('BBBBBBBB'))


li = []
n = 8
h = 0
st = 'BBBBBBBB'
for i in range(n):
	s = input()
	if s == st:
		h += 1
	li.append(s)
if h == 8:
	print(8)
else:
	v = 0
	f = 0
	for i in range(n):
		for j in range(n):
			if li[j][i] != 'B':
				f = 1
				break
		if f == 0:
			v += 1
		f = 0
	print(h + v)


paint = 0
column = [''] * 8
for n in range(8):
	row = input()
	paint += 'W' not in row
	for i in range(8):
		column[i] += row[i]
for c in column:
	paint += 'W' not in c
if paint == 16:
	paint = 8
print(paint)


m = [input() for i in range(8)]
r = sum([1 for i in range(8) if m[i] == 'B' * 8])
c = sum([1 for i in range(8) if sum([1 for k in range(8) if m[k][i] == 'B']) == 8])
if max(r, c) == 8:
	print(8)
else:
	print(r + c)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
g = []
st = set()
x = ''
c = 0
z1 = []
for i in range(8):
	s = STR()
	if len(set(s)) == 1 and s[0] == 'B':
		c += 1
		z1.append(i)
	for i in s:
		x = i
		st.add(i)
	g.append(s)
if len(st) == 1 and x == 'B':
	print(8)
	exit(0)
if len(st) == 1 and x == 'W':
	print(0)
	exit(0)
z2 = []
for i in range(8):
	for j in range(8):
		if g[i][j] == 'B':
			if len(z2) == 0 and len(z1) == 0:
				c += 1
				z2.append(j)
			elif i in z1 or j in z2:
				continue
			else:
				c += 1
				z2.append(j)
print(c)


def match_strokes(board):
	rows = ['W' for x in range(8)]
	columns = ['W' for x in range(8)]
	for (i, row) in enumerate(board):
		if row == 'B' * 8:
			rows[i] = 'B'
		elif 'B' in row:
			for (j, col) in enumerate(row):
				if col == 'B':
					columns[j] = 'B'
	print((rows + columns).count('B'))
match_strokes([input() for x in range(8)])


k = 0
v = True
for i in range(8):
	s = input()
	if s == 'BBBBBBBB':
		k += 1
	elif v:
		k += s.count('B')
		v = False
print(k)


m = []
for i in range(8):
	s = input()
	m.append([s[j] for j in range(len(s))])
l = []
c = []
check = 0
for i in range(8):
	check = 0
	for j in range(8):
		if m[i][j] == 'B':
			check += 1
	if check == 8:
		l.append(i)
for j in range(8):
	check = 0
	for i in range(8):
		if m[i][j] == 'B':
			check += 1
	if check == 8:
		c.append(j)
if len(c) == 8 or len(l) == 8:
	print(8)
else:
	print(len(c) + len(l))


grid = [input() for _ in range(8)]
result = grid.count('B' * 8)
grid = [''.join(l) for l in zip(*grid)]
result += grid.count('B' * 8)
result = 8 if result == 16 else result
print(result)


a = []
ans = 0
for i in range(8):
	line = list(input())
	a.append(line)
	if not 'W' in line:
		ans += 1
at = []
for i in range(8):
	temp = []
	for j in range(8):
		temp.append(a[j][i])
	at.append(temp)
for i in range(8):
	if not 'W' in at[i]:
		ans += 1
if ans == 16:
	print(8)
else:
	print(ans)


(s, m, c) = (0, 0, 0)
for i in range(8):
	t = input()
	if t == 'BBBBBBBB':
		s += 1
	else:
		m = t.count('B')
print(s + m)


ln = 8
wc = 'W'
bc = 'B'

def ss(s, pos, ns):
	return s[:pos] + ns + s[pos + 1:]

def ish(s, cl):
	cl = wc if cl == bc else bc
	for c in s:
		if c == cl:
			return 0
	return 1

def isv(v, x, cl):
	cl = wc if cl == bc else bc
	for c in range(ln):
		if v[c][x] == cl:
			return 0
	return 1

def pth(v, z, cl):
	v[c] = ln * cl

def ptv(v, x, cl):
	for c in range(ln):
		v[c] = ss(v[c], x, cl)
v = []
for c in range(ln):
	s = input()
	v.append(s)
pv = [x for x in ln * [ln * wc]]
res = 0
for c in range(ln):
	if ish(v[c], bc) and (not ish(pv[c], bc)):
		pth(pv, c, bc)
		res += 1
for c in range(ln):
	if isv(v, c, bc) and (not isv(pv, c, bc)):
		ptv(pv, c, bc)
		res += 1
print(res)


a = list(input())
b = list(input())
c = list(input())
d = list(input())
q = list(input())
w = list(input())
e = list(input())
r = list(input())
z = 0
m = 0
for i in range(1, 8):
	if a[i - 1] == a[i] and a[i] == 'B':
		z += 1
	if z == 7:
		m += 1
z = 0
for i in range(1, 8):
	if b[i - 1] == b[i] and b[i] == 'B':
		z += 1
	if z >= 7:
		m += 1
z = 0
for i in range(1, 8):
	if c[i - 1] == c[i] and c[i] == 'B':
		z += 1
	if z >= 7:
		m += 1
z = 0
for i in range(1, 8):
	if d[i - 1] == d[i] and d[i] == 'B':
		z += 1
	if z >= 7:
		m += 1
z = 0
for i in range(1, 8):
	if q[i - 1] == q[i] and q[i] == 'B':
		z += 1
	if z == 7:
		m += 1
z = 0
for i in range(1, 8):
	if w[i - 1] == w[i] and w[i] == 'B':
		z += 1
	if z == 7:
		m += 1
z = 0
for i in range(1, 8):
	if e[i - 1] == e[i] and e[i] == 'B':
		z += 1
	if z == 7:
		m += 1
z = 0
for i in range(1, 8):
	if r[i - 1] == r[i] and r[i] == 'B':
		z += 1
	if z == 7:
		m += 1
if m != 8:
	for i in range(8):
		if a[i] == b[i] and b[i] == c[i] and (c[i] == d[i]) and (d[i] == q[i]) and (q[i] == w[i]) and (w[i] == e[i]) and (e[i] == r[i]) and (a[i] == 'B'):
			m += 1
print(m)


s = []
for n in range(8):
	s.append(list(input()))
d = ['B'] * 8
l = 0
j = 0
for n in range(8):
	if s[n] == d:
		l += 1
	elif j == 0:
		l += s[n].count('B')
		j = 1
print(l)


br = [input() for i in range(8)]
bc = [''.join((r[j] for r in br)) for j in range(8)]
v = br.count('B' * 8) + bc.count('B' * 8)
print(v if v < 16 else 8)


chess = [input().count('B') for i in range(8)]
print(chess.count(8) + min(chess) % 8)


chess = []
strokes = 0
filled = True
for i in range(8):
	row = input()
	if row.count('W') == 0:
		strokes += 1
	elif filled:
		filled = False
		strokes += row.count('B')
print(strokes)


board = []
painted_ranks = 0
painted_files = 0
for i in range(8):
	rank = input()
	painted = rank.count('B')
	if painted == 8:
		painted_ranks += 1
	board.append(rank)
for i in range(8):
	x = 0
	for j in range(8):
		if board[j][i] == 'B':
			x += 1
	if x == 8:
		painted_files += 1
if painted_ranks == 8:
	print(8)
else:
	print(painted_files + painted_ranks)


board = []
out = 0
for i in range(8):
	row = input()
	board.append(row)
complete = True
for i in range(8):
	if board[i] != 'BBBBBBBB':
		complete = False
		break
if complete:
	out = 8
	print(out)
else:
	for i in range(8):
		same = True
		for j in range(8):
			if board[i][j] != 'B':
				same = False
				break
		if same:
			out += 1
	for i in range(8):
		same = True
		for j in range(8):
			if board[j][i] != 'B':
				same = False
				break
		if same:
			out += 1
	print(out)


(a, s) = ([], 0)
for i in range(8):
	b = list(input())
	if b.count('W') == 0:
		s = s + 1
	a.append(b)
if s == 8:
	print(s)
else:
	k = a[0].count('B')
	for i in range(len(a)):
		if a[i].count('B') < k:
			k = a[i].count('B')
	print(s + k)


t = []
h = 0
for k in range(8):
	f = list(input())
	t.append(f)
	if f.count('W') == 0:
		h += 1
y = []
if h == 8:
	print(8)
else:
	for u in range(8):
		x = []
		for j in range(8):
			x.append(t[j][u])
		y.append(x)
	d = 0
	for i in t:
		if i.count('W') == 0:
			d += 1
	for j in y:
		if j.count('W') == 0:
			d += 1
	print(d)


def parse_input():
	temp_string = []
	for i in range(8):
		temp_string.append([x for x in input()])
	return temp_string

def transform_matrix(input_matrix):
	output_matrix = []
	for i in range(8):
		temp_row_matrix = []
		for j in range(8):
			if input_matrix[i][j] == 'W':
				temp_row_matrix.append(1)
			else:
				temp_row_matrix.append(0)
		output_matrix.append(temp_row_matrix)
	return output_matrix

def counting_lines(input_strigs):
	count_lines_for_art = 0
	for i in range(8):
		count_w_in_row = 0
		for j in range(8):
			count_w_in_row += input_strigs[i][j]
		if count_w_in_row == 0:
			count_lines_for_art += 1
	for j in range(8):
		count_w_in_col = 0
		for i in range(8):
			count_w_in_col += input_strigs[i][j]
		if count_w_in_col == 0:
			count_lines_for_art += 1
	if count_lines_for_art == 16:
		return 8
	else:
		return count_lines_for_art
count_lines = counting_lines(transform_matrix(parse_input()))
print(count_lines)


c = [input() for _ in range(8)]
h = sum((all((c[_][i] == 'B' for i in range(8))) for _ in range(8)))
v = sum((all((c[i][_] == 'B' for i in range(8))) for _ in range(8)))
if h == 8 or v == 8:
	print(8)
else:
	print(h + v)


(s, cnt) = ([], 0)
for i in range(8):
	l = input()
	if l == 'B' * 8:
		cnt += 1
	s.append(list(l))
if sum([''.join(j) == 'B' * 8 for j in s]) == 8:
	print(8)
	exit(0)
for i in range(8):
	test = ''
	for j in range(8):
		test += s[j][i]
	if test == 'B' * 8:
		cnt += 1
print(cnt)


x = y = 0
for _ in range(8):
	n = input().count('B')
	if n < 8:
		y = n
	else:
		x += 1
print(x + y)


n = [[], [], [], [], [], [], [], []]
n[0] = input()
n[1] = input()
n[2] = input()
n[3] = input()
n[4] = input()
n[5] = input()
n[6] = input()
n[7] = input()
c = 0
d = 0
for i in range(0, 8):
	if 'W' not in n[i]:
		c += 1
for i in range(0, 8):
	d = 0
	for j in range(0, 8):
		if n[0][i] == 'W':
			continue
		elif n[j][i] == 'B':
			d += 1
			if d == 8:
				d = 0
				c += 1
if c == 16:
	c = int(c / 2)
print(c)


b = 0
a = 0
for i in range(8):
	k = input()
	n = k.count('B')
	if n < 8:
		a = n
	else:
		b += 1
print(a + b)


board = [[0] * 8] * 8
for i in range(8):
	aux = input()
	for j in range(8):
		board[i] = aux
count = 0
for i in board:
	if i.count('B') == 8:
		count += 1
if count == 8:
	print(8)
	exit(0)
for i in range(8):
	aux_count = 0
	for j in range(8):
		if board[j][i] == 'B':
			aux_count += 1
	if aux_count == 8:
		count += 1
print(count)


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=lambda : 0):
	return defaultdict(lambda : defaultdict(d))

def dd0(d=lambda : 0):
	return defaultdict(d)

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def fltn(a):
	(i for sub in a for i in sub)

def yn(x):
	return 'YES' if x else 'NO'
from itertools import accumulate
from itertools import groupby

def grp(x):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x))
import math

def rnar():
	return (*rrl(), rrl())

def rn():
	return (*rrl(),)

def dpp(*args):
	print(*args)

def read():
	l = [rr() for _ in range(8)]
	return (l,)

def solve(l):
	vert = 99
	for row in l:
		vert = min(vert, row.count('B'))
	horiz = 99
	for x in range(8):
		cur_b = 0
		for y in range(8):
			if l[y][x] == 'B':
				cur_b += 1
		horiz = min(horiz, cur_b)
	if vert == 8:
		horiz = 0
	ans = vert + horiz
	return ans
test_count = 1
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


n = 0
counted = False
for i in range(8):
	a = input()
	if a == 'BBBBBBBB':
		n += 1
	elif not counted:
		n += a.count('B')
		counted = True
print(n)


chess = []
for i in range(8):
	chess.append(input())
r = [1] * 8
c = [1] * 8
for i in range(8):
	for j in range(8):
		if chess[i][j] == 'W':
			(r[i], c[j]) = (0, 0)
ans = 0
for i in range(8):
	ans += r[i] + c[i]
if ans == 16:
	print(8)
else:
	print(ans)


(board, columns, rows) = ([], [], [])
for i in range(8):
	line = []
	for char in input():
		line.append(True) if char == 'B' else line.append(False)
	board.append(line)
	if False not in line:
		rows.append(i)
for i in range(8):
	white = False
	for j in range(8):
		if not board[j][i]:
			white = True
	if not white:
		columns.append(i)
brute = [[False for i in range(8)] for j in range(8)]
strikes = 0
for line in rows:
	strikes += 1
	brute[line] = [True for i in range(8)]
	if brute == board:
		break
if brute != board:
	for column in columns:
		strikes += 1
		for row in brute:
			row[column] = True
		if brute == board:
			break
print(strikes)


l = []
for i in range(8):
	l.append(list(input()))
l2 = []
for i in range(8):
	l3 = []
	for j in range(8):
		l3.append(l[j][i])
	l2.append(l3)
c = 0
for i in l:
	if i == ['B'] * 8:
		c += 1
for i in l2:
	if i == ['B'] * 8:
		c += 1
if c == 16:
	c = 8
print(c)


def k_chess():
	board = ''.join([input().strip() for i in range(8)])
	count = 0
	for i in range(8):
		for j in range(0, 57, 8):
			if board[i + j] == 'W':
				break
		else:
			count += 1
	if count == 8:
		print(count)
		return
	for i in range(0, 57, 8):
		for j in range(8):
			if board[i + j] == 'W':
				break
		else:
			count += 1
	print(count)
	return
k_chess()


a = []
for i in range(8):
	a.append(input())
(r, c) = (set(), set())
for i in range(8):
	for j in range(8):
		if a[i][j] == 'W':
			r.add(i)
			c.add(j)
answer = 16 - len(r) - len(c)
if answer == 16:
	answer = 8
print(answer)


def main():
	grid = []
	for _ in range(8):
		grid.append(input())
	if all((all((c == 'B' for c in row)) for row in grid)):
		print('8')
		return
	rows = []
	for (i, row) in enumerate(grid):
		if all((c == 'B' for c in row)):
			rows.append(i)
	cols = []
	for j in range(8):
		if all((grid[i][j] == 'B' for i in range(8))):
			cols.append(j)
	print(len(rows) + len(cols))
main()


l = []
lp = []
br = 0
for i in range(8):
	s = input()
	l.append(list(s))
	if len(set(s)) == 1 and 'B' in s:
		br += 1
		lp.append([1 for j in range(8)])
	else:
		lp.append([0 for j in range(8)])
for i in range(8):
	for j in range(8):
		if l[i][j] == 'B' and lp[i][j] == 0:
			for k in range(8):
				if lp[k][j] == 0:
					lp[k][j] = 1
			br += 1
print(br)


a = []
for i in range(0, 8):
	a.append(input())
t1 = 0
t2 = 0
for i in range(0, 8):
	if a[i].count('B') == 8:
		t1 += 1
	else:
		t2 = a[i].count('B')
print(t1 + t2)


c = []
for i in range(8):
	c.append(input().count('B'))
print(min(c) % 8 + c.count(8))


filas = 0
columnas = 0
total_lineas = 0
matriz = list()
for i in range(8):
	matriz.append(list(input()))
for i in range(8):
	nb = 0
	for j in range(8):
		if matriz[i][j] == 'B':
			nb = nb + 1
		else:
			break
	if nb == 8:
		filas = filas + 1
if filas == 8:
	print(8)
else:
	for j in range(8):
		nb = 0
		for i in range(8):
			if matriz[i][j] == 'B':
				nb = nb + 1
			else:
				break
		if nb == 8:
			columnas = columnas + 1
	total_lineas = filas + columnas
	print(total_lineas)


a = [''] * 8
for i in range(8):
	a[i] = input()
a = list(map(lambda a: a.count('B'), a))
b = set(a)
c = 0
for i in b:
	if i == 8:
		c += a.count(8)
	else:
		c += i
print(c)


def isRowSlash(matrix, r):
	row = ''
	for i in range(8):
		row += matrix[r][i]
	goal = 'B' * 8
	return row == goal

def isColSlash(matrix, c):
	col = ''
	for i in range(8):
		col += matrix[i][c]
	goal = 'B' * 8
	return col == goal
matrix = []
for _ in range(8):
	row = input()
	matrix.append(row)
res = 0
i = 0
j = 0
while i < 8 and j < 8:
	curr = matrix[i][j]
	if curr == 'B':
		if j == 0:
			if isRowSlash(matrix, i):
				res += 1
		if i == 0:
			if isColSlash(matrix, j):
				res += 1
	if j == 7:
		j = 0
		i += 1
	else:
		j += 1
if res == 16:
	print(8)
else:
	print(res)


x = []
sum = 0
counter = 0
for i in range(8):
	x.append(input())
for i in range(8):
	counter = 1
	for j in range(8):
		if x[j][i] == 'B' and counter == 1:
			counter == 1
		else:
			counter = 0
		if j == 7 and counter == 1:
			sum += 1
for i in range(8):
	counter = 1
	for j in range(8):
		if x[i][j] == 'B' and counter == 1:
			counter == 1
		else:
			counter = 0
		if j == 7 and counter == 1:
			sum += 1
if sum == 16:
	print(8)
else:
	print(sum)


brd = [input() for i in range(8)]
ans = 0
for i in range(8):
	if all([brd[i][j] == 'B' for j in range(8)]):
		ans += 1
	if all([brd[j][i] == 'B' for j in range(8)]):
		ans += 1
if ans == 16:
	ans = 8
print(ans)


def B_line(line):
	count = 0
	for i in range(0, len(line)):
		if line[i] == 'B':
			count = count + 1
	if count == 8:
		return True
output = 0
rows = []
for x in range(0, 8):
	line = input()
	row = list(line)
	rows.append(row)
	line_B = B_line(rows[x])
	if line_B == True:
		output = output + 1
if output != 8:
	for j in range(0, 8):
		count = 1
		for i in range(0, 7):
			if rows[i][j] == rows[i + 1][j] == 'B':
				count = count + 1
			else:
				break
		if count == 8:
			output = output + 1
print(output)


def main():
	a = [input().count('B') for i in range(8)]
	print(min(a) % 8 + a.count(8))
main()


h = []
v = []
for i in range(8):
	s = input()
	sl = [i for i in s]
	h.append(sl)
for i in range(8):
	x = []
	for j in range(8):
		x.append(h[j][i])
	v.append(x)
ans = 0
for i in h:
	x = list(set(i))
	if len(x) == 1 and x[0] == 'B':
		ans += 1
for i in v:
	x = list(set(i))
	if len(x) == 1 and x[0] == 'B':
		ans += 1
if ans == 16:
	print(8)
else:
	print(ans)


from sys import stdin
a = stdin.read().splitlines()
Switch = 0
row = 0
column = 0
answer = 0
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 'W':
			Switch = 1
			row = i
			column = j
			break
	if Switch == 1:
		break
if Switch == 0:
	print(8)
else:
	for square in a[row]:
		if square == 'B':
			answer += 1
	for k in range(len(a[column])):
		if a[k][column] == 'B':
			answer += 1
	print(answer)


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
h = v = 0
for i in range(8):
	row = rl()
	k = row.count('B')
	if k == 8:
		h += 1
	elif v == 0:
		v += k
print(h + v)


import math
__author__ = 'Obriel Muga'
list_matrix = list()
rows = 0
col = 0
for i in range(8):
	linea = input()
	linea = linea.replace('W', '0')
	linea = linea.replace('B', '1')
	lista = list(linea)
	lista = list(map(int, lista))
	if sum(lista) == 8:
		rows = rows + 1
	else:
		col = sum(lista)
print(rows + col)


import itertools
import sys

def main():
	solve()

def solve():
	data = sys.stdin.readlines()
	board = parse(data)
	output = calc_board(board)
	print(output)

def parse(data):
	return tuple((tuple((c == 'B' for c in line.rstrip())) for line in data))

def calc_board(board):
	horiz_strike = [True for _ in range(8)]
	vert_strike = [True for _ in range(8)]
	for (i, line) in enumerate(board):
		for (j, c) in enumerate(line):
			if not c:
				horiz_strike[i] = False
				vert_strike[j] = False
	if all(horiz_strike) or all(vert_strike):
		return 8
	else:
		return sum(horiz_strike) + sum(vert_strike)
main()


V = [input().count('B') for _ in range(8)]
cnt = 0
for i in V:
	if i == 8:
		cnt += 1
if min(V) != 8:
	cnt += min(V)
print(cnt)


field = [input() for i in range(8)]
rows = sum((all((x == 'B' for x in row)) for row in field))
cols = sum((all((field[i][j] == 'B' for i in range(8))) for j in range(8)))
if rows == 8:
	print(8)
else:
	print(rows + cols)


import sys
import math
import collections
l = []
for i in range(8):
	l.append(list(input()))
c = 0
row = [0] * 8
for i in range(8):
	if l[i] == ['B'] * 8:
		c += 1
		row[i] = 1
if c == 8:
	print(c)
else:
	k = row.index(0)
	for j in range(8):
		if l[k][j] == 'B':
			c += 1
	print(c)


n = 8
chess = []
for _ in range(n):
	chess.append(input())
(row, col) = (0, 0)
for i in range(n):
	(f, cnt) = (0, 0)
	for j in range(n):
		if chess[i][j] == 'B':
			cnt += 1
		else:
			f = 1
	if f == 0:
		row += 1
	else:
		col = cnt
print(row + col)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict, deque
import heapq
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
l = [input().count('B') for i in range(8)]
print(min(l) % 8 + l.count(8))


brd = [input() for _ in range(8)]
ans = 0
for i in range(8):
	if brd[i] == 'B' * 8:
		ans += 1
	if set([x[i] for x in brd]) == {'B'}:
		ans += 1
if ans == 16:
	ans = 8
print(ans)


data = [input() for _ in range(8)]
ans = sum([1 for i in range(8) if all([1 if j == 'B' else 0 for j in data[i]])])
if ans == 8:
	print(8)
else:
	ans += sum([1 for i in range(8) if all((1 if k == 'B' else 0 for k in [data[j][i] for j in range(8)]))])
	print(ans)


lines = [input() for i in range(8)]
res = 0
for i in range(8):
	for j in range(8):
		if lines[i][j] == 'W':
			break
		if j == 7:
			res += 1
for i in range(8):
	for j in range(8):
		if lines[j][i] == 'W':
			break
		if j == 7:
			res += 1
res_b = 0
for i in range(8):
	for j in range(8):
		if lines[i][j] == 'B':
			res_b += 1
if res_b == 8 * 8:
	print(8)
else:
	print(res)


def main():
	table = [input().replace(' ', '') for _ in range(8)]
	for i in range(8):
		temp = ''
		for j in range(8):
			temp += table[j][i]
		table.append(temp)
	print(table.count('BBBBBBBB')) if table.count('BBBBBBBB') != 16 else print(8)
main()


row = []
col = []
for i in range(8):
	col.append('')
for i in range(8):
	x = input()
	row.append(x)
	for i in range(8):
		col[i] += x[i]

def isblack(s):
	for c in s:
		if c != 'B':
			return False
	return True
a = 0
b = 0
for x in row:
	if isblack(x):
		a += 1
if a == 8:
	print(8)
else:
	for y in col:
		if isblack(y):
			b += 1
	print(a + b)


def solve(m):
	vert = 0
	hor = 0
	for i in range(8):
		is_vert = True
		is_hor = True
		for j in range(8):
			if m[i][j] != 'B':
				is_hor = False
			if m[j][i] != 'B':
				is_vert = False
		if is_vert:
			vert = vert + 1
		if is_hor:
			hor = hor + 1
	return vert + hor if hor != 8 or hor != vert else hor
board = []
for i in range(8):
	board.append(input())
print(solve(board))


c = 0
r = 0
k = 0
for _ in range(8):
	n = input()
	if n == 'BBBBBBBB':
		c += 1
	else:
		for i in n:
			if i == 'B':
				r += 1
		k += 1
if k == 0:
	print(8)
else:
	print(c + r // k)


arr = []
(row, col) = (0, 0)
for i in range(0, 8):
	s = input()
	if s == 'BBBBBBBB':
		row += 1
	arr.append(list(s))
res = 0
if row == 8:
	res = 8
else:
	for j in range(0, 8):
		temp = ''
		for i in range(0, 8):
			temp += arr[i][j]
		if temp == 'BBBBBBBB':
			col += 1
	res = col + row
print(res)


n = 8
g = [list(input()) for _ in range(n)]
r = set()
c = set()
for i in range(n):
	if g[i].count('B') == n:
		r.add(i)
	else:
		c |= set((j for j in range(n) if g[i][j] == 'B'))
print(len(r) + len(c))


class A:

	def solve(self):
		board = []
		for i in range(8):
			board.append(input())
		painted_black = [[0 for i in range(8)] for j in range(8)]
		strokes = 0
		for i in range(8):
			if len(set(board[i])) == 1 and 'B' in set(board[i]):
				strokes += 1
				painted_black[i] = [1 for i in range(8)]
		for i in range(8):
			if len(set([board[x][i] for x in range(8)])) == 1 and 'B' in set([board[x][i] for x in range(8)]) and (0 in set([painted_black[x][i] for x in range(8)])):
				strokes += 1
		print(strokes)
A().solve()


ar = ['' for i in range(8)]
k = 0
for i in range(8):
	a = ar[i] = input()
	if a == 'BBBBBBBB':
		k += 1
ary = ['' for i in range(8)]
for i in range(8):
	for j in range(8):
		ary[i] += ar[j][i]
	if ary[i] == 'BBBBBBBB':
		k += 1
if k == 16:
	k = 8
print(k)


list_positions = []
for x in range(8):
	letters = input()
	list_positions.append(letters)
quantidade = 0
for x in range(8):
	i_B = 0
	for y in range(8):
		if list_positions[x][y] == 'B':
			i_B += 1
		if i_B == 8:
			quantidade += 1
for x in range(8):
	i_B = 0
	for y in range(8):
		if list_positions[y][x] == 'B':
			i_B += 1
		if i_B == 8:
			quantidade += 1
if quantidade == 16:
	quantidade = 8
print(quantidade)


m1 = []
m2 = ['' for i in range(8)]
for i in range(8):
	row = input()
	m1.append(row)
	for j in range(8):
		m2[j] += row[j]
cnt1 = m1.count('B' * 8)
cnt2 = m2.count('B' * 8)
if cnt1 == 8:
	print(8)
else:
	print(cnt1 + cnt2)


grid = []
for i in range(8):
	grid.append(input().strip())
num_rows = 0
num_cols = 0

def all_Bs(line):
	for c in line:
		if c != 'B':
			return False
	return True

def all_Bs_column(index):
	for i in range(8):
		if grid[i][index] != 'B':
			return False
	return True
for line in grid:
	if all_Bs(line):
		num_rows += 1
for i in range(8):
	if all_Bs_column(i):
		num_cols += 1
result = num_rows + num_cols
if result == 16:
	print(8)
else:
	print(result)


matrix = []
for i in range(8):
	matrix.append(input())
h = []
r = []
for i in range(8):
	for j in range(8):
		if matrix[i][j] == 'B':
			if 'W' in matrix[i]:
				if j not in h:
					h.append(j)
			elif i not in r:
				r.append(i)
print(len(h) + len(r))


def main():
	hs = []
	(t, f) = (0, 0)
	for i in range(8):
		hs.append(input().split())
	for j in range(8):
		check = 0
		trak = 0
		for jj in range(8):
			if hs[j][0][jj] == 'B':
				trak += 1
			if hs[jj][0][j] == 'B':
				check += 1
		if trak >= 8:
			t += 1
		if check >= 8:
			t += 1
	if t == 16:
		t = int(t / 2)
	print(t)
main()


def CF_7A():
	board = []
	ans = 0
	for i in range(0, 8):
		board.append(' '.join(input()).split())
	for i in range(0, 8):
		if board[i] == ['B'] * 8:
			ans += 1
	for j in range(0, 8):
		flag = 1
		for i in range(0, 8):
			if board[i][j] != 'B':
				flag = 0
				break
		if flag == 1:
			ans += 1
	if ans == 16:
		ans = 8
	print(ans)
	return
CF_7A()


import sys
num_black_rows = 0
other_row = 'WWWWWWWW'
for i in range(8):
	line = sys.stdin.readline().rstrip()
	if line == 'BBBBBBBB':
		num_black_rows += 1
	else:
		other_row = line
print(num_black_rows + other_row.count('B'))


s = []
for i in range(8):
	s.append(input())
num = 0
for i in s:
	if i == 'BBBBBBBB':
		num = num + 1
	else:
		w = i
if num == 8:
	print(8)
else:
	for i in w:
		if i == 'B':
			num = num + 1
	print(num)


l = []
for _ in range(8):
	l.append(input())
r = set()
c = set()
for i in range(8):
	for j in range(8):
		if l[i][j] == 'W':
			r.add(i)
			c.add(j)
if not r and (not c):
	print(8)
else:
	print(16 - len(r) - len(c))


a = [0] * 8
k = 0
for _ in range(8):
	i = input()
	if i == 'B' * 8:
		k += 1
	else:
		for e in range(8):
			if i[e] == 'B':
				a[e] = 1
print(k + sum(a))


ans = 0
arr = [None] * 8
for i in range(8):
	arr[i] = list(input())
	if arr[i].count('B') == 8:
		arr[i] = ['W'] * 8
		ans += 1
for i in range(8):
	for j in range(8):
		if arr[i][j] == 'B':
			ans += 1
			for k in range(8):
				arr[k][j] = 'W'
print(ans)


c = 0
b = 9
for i in range(8):
	ec = input()
	cc = ec.count('B')
	if cc == 8:
		c += 1
	b = min(b, cc)
if c == 8:
	print(8)
else:
	print(b + c)


a = [input().count('B') for i in range(8)]
if min(a) != 8:
	print(min(a) + a.count(8))
else:
	print(a.count(8))


board = []
for i in range(8):
	board.append(list(input()))

def all_black(lst):
	for elem in lst:
		if elem == 'W':
			return False
	return True
columns = []
for i in range(8):
	columns.append([])
	for row in board:
		columns[i].append(row[i])
strokes = 0
for col in columns:
	if all_black(col):
		strokes += 1
for row in board:
	if all_black(row):
		strokes += 1
if strokes == 16:
	strokes = 8
print(strokes)