Minesweeper

No attempts yetTime limit1sMemory limit128 MB

Problem

Minesweeper is a game about finding the mines hidden in a 2×N2 \times N grid. The number written in a cell says how many mines sit in the cells that touch it horizontally, vertically or diagonally. A cell known to hold a mine is marked *, and a cell that is still covered is marked #. The first row holds only digits, the second row holds only * and #, and every mine is in the second row.

12110
##*##

This 2×52 \times 5 grid holds two mines. One is hidden under the first cell of the second row, and the other is the revealed cell in the middle.

Given a 2×N2 \times N grid, count the mines in it, including the ones already marked *.

Input

The first line has the number of test cases TT (1T101 \le T \le 10). Each test case starts with the grid size NN (1N1001 \le N \le 100) on its own line, followed by two lines that hold the grid. The first of those lines has only digits, the second has only * and #, and neither line has a space in it. Every input describes a grid that some real mine placement can produce.

Output

For each test case, print the number of mines in the grid on its own line. If several mine counts are possible, print the largest one.