Under construction

Still being built. Things may change

Chino's Latte Art (Easy)

Interview

Time limit1sMemory limit1024 MB

Summary
Given a grid of cream cells, decide whether they form exactly one N x N square with an M x M corner removed, with no holes or extra lumps.
Level

Easy3 of 10

Topics
Implementation, Brute force, Matrix
Solved
No attempts yet

Problem

Chino is practicing making heart-shaped latte art. Cocoa happened to see the many traces of Chino's practice and became curious how many heart-shaped latte art pieces there are. Write a program that determines whether the cream on a latte is heart-shaped, for Cocoa.

Heart shape

Chino's latte art is given as a two-dimensional grid divided into unit squares. # is a square fully filled with cream, and . is a square with no cream.

Two positive integers NN and MM (0<M<N0<M<N) define a heart as an N×NN\times N square with an M×MM\times M square removed from one of its four corners.

The following is a heart for N=5N=5, M=2M=2.

###..
###..
#####
#####
#####

A latte is counted as a heart only when exactly one shape defined above is placed on it. If the cream has a hole, or if it consists of several separate lumps (including the case where each lump is heart-shaped), it is not considered a heart.

Input

The first line contains the number of test cases TT (1≤T≤1001\le T\le 100). The next lines contain TT test cases in the following format.

The first line of each test case contains the number of rows RR and columns CC of the grid, separated by a space. (2≤R,C≤102\le R, C\le 10)

The next RR lines contain strings of length CC representing rows 11 to RR of the grid. Each string consists only of # and ..

Output

For each test case, print 1 if the latte art is a heart, and 0 otherwise, one per line.

Examples1

  1. Example 1

    Input
    3
    5 5
    ###..
    ###..
    #####
    #####
    #####
    10 10
    ...#.#....
    ..#.#.#...
    ..#.#.#...
    ..#####...
    .#.....#..
    .#.#.#.#..
    .#..#..#..
    .#.###.#..
    .#.....#..
    ..#####...
    4 8
    ........
    .##.....
    .#......
    ........
    
    Expected output
    1
    0
    1