```
puyo = []
for _ in range(12):
line = [c for c in input().strip()]
puyo.append(line)
explode = 1
total_explode = 0
while explode:
# use bfs for explosion
visited = [[0]*6 for _ in range(12)]
dirs = [(1,0),(-1,0),(0,1),(0,-1)]
explode = 0
for i in range(12):
for j in range(6):
if puyo[i][j] == '.':
visited[i][j] = 1
if visited[i][j] == 0:
q = [(i,j,puyo[i][j])]
visited[i][j] = 1
rocks = [(i,j)]
while q:
x,y,c = q.pop(0)
for dx,dy in dirs:
if 0<=x+dx<12 and 0<=y+dy<6:
if visited[x+dx][y+dy]==0 and puyo[x+dx][y+dy] == c:
q.append((x+dx,y+dy,c))
visited[x+dx][y+dy] = 1
rocks.append((x+dx,y+dy))
if len(rocks) > 3:
for x,y in rocks:
puyo[x][y] = '.'
explode = 1
# gravity
if explode:
total_explode += 1
for j in range(6):
for i in reversed(range(12)):
if puyo[i][j] == '.':
for k in reversed(range(i)):
if puyo[k][j] != '.':
puyo[i][j] = puyo[k][j]
puyo[k][j] = '.'
break
print(total_explode)
```