#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
int n, wyn;
char T[ 1007 ] [ 1007 ] ;
int ix;
int X[ 10000000 ] ;
int Y[ 10000000 ] ;
void rek( int x, int y)
{
if ( T[ x] [ y] ! = '@' ) return ;
if ( x> 0 && T[ x- 1 ] [ y] == '.' ) { wyn-- ; T[ x- 1 ] [ y] = '@' ; X[ ix] = x- 1 ; Y[ ix++ ] = y; }
if ( x< n- 1 && T[ x+ 1 ] [ y] == '.' ) { wyn-- ; T[ x+ 1 ] [ y] = '@' ; X[ ix] = x+ 1 ; Y[ ix++ ] = y; }
if ( y> 0 && T[ x] [ y- 1 ] == '.' ) { wyn-- ; T[ x] [ y- 1 ] = '@' ; X[ ix] = x; Y[ ix++ ] = y- 1 ; }
if ( y< n- 1 && T[ x] [ y+ 1 ] == '.' ) { wyn-- ; T[ x] [ y+ 1 ] = '@' ; X[ ix] = x; Y[ ix++ ] = y+ 1 ; }
if ( x> 0 && y> 0 && T[ x- 1 ] [ y- 1 ] == '.' ) { wyn-- ; T[ x- 1 ] [ y- 1 ] = '@' ; X[ ix] = x- 1 ; Y[ ix++ ] = y- 1 ; }
if ( x< n- 1 && y< n- 1 && T[ x+ 1 ] [ y+ 1 ] == '.' ) { wyn-- ; T[ x+ 1 ] [ y+ 1 ] = '@' ; X[ ix] = x+ 1 ; Y[ ix++ ] = y+ 1 ; }
if ( y> 0 && x < n- 1 && T[ x+ 1 ] [ y- 1 ] == '.' ) { wyn-- ; T[ x+ 1 ] [ y- 1 ] = '@' ; X[ ix] = x+ 1 ; Y[ ix++ ] = y- 1 ; }
if ( y< n- 1 && x> 0 && T[ x- 1 ] [ y+ 1 ] == '.' ) { wyn-- ; T[ x- 1 ] [ y+ 1 ] = '@' ; X[ ix] = x- 1 ; Y[ ix++ ] = y+ 1 ; }
}
int main( )
{
int t;
scanf ( "%d\n " , & t) ;
wyn = 0 ;
for ( int tx = 0 ; tx < t; tx++ )
{
ix= 0 ;
scanf ( "%d\n " , & n) ;
wyn = n* n;
char a;
for ( int i = 0 ; i < n; i++ )
{
for ( int j = 0 ; j < n; j++ )
{
a = getchar ( ) ;
T[ i] [ j] = a;
}
char foo = getchar ( ) ;
}
/*
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
printf("%c", T[i][j]);
printf("\n");
}*/
//lewa
for ( int i = 0 ; i < n; i++ ) if ( T[ 0 ] [ i] == '.' ) { wyn-- ; T[ 0 ] [ i] = '@' ; X[ ix] = 0 ; Y[ ix++ ] = i; }
//prawa
for ( int i = 0 ; i < n; i++ ) if ( T[ n- 1 ] [ i] == '.' ) { wyn-- ; T[ n- 1 ] [ i] = '@' ; X[ ix] = n- 1 ; Y[ ix++ ] = i; }
//dol
for ( int i = 0 ; i < n; i++ ) if ( T[ i] [ 0 ] == '.' ) { wyn-- ; T[ i] [ 0 ] = '@' ; X[ ix] = i; Y[ ix++ ] = 0 ; }
//gora
for ( int i = 0 ; i < n; i++ ) if ( T[ i] [ n- 1 ] == '.' ) { wyn-- ; T[ i] [ n- 1 ] = '@' ; X[ ix] = i; Y[ ix++ ] = n- 1 ; }
for ( int i = 0 ; i < ix; i++ ) rek( X[ i] , Y[ i] ) ;
/*
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
printf("%c", T[i][j]);
printf("\n");
}*/
printf ( "%d\n " , wyn) ;
}
return 0 ;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKaW50IG4sIHd5bjsKIApjaGFyIFRbMTAwN11bMTAwN107CiAKaW50IGl4OwppbnQgWFsxMDAwMDAwMF07CmludCBZWzEwMDAwMDAwXTsKIAp2b2lkIHJlayhpbnQgeCwgaW50IHkpCnsKCWlmIChUW3hdW3ldICE9ICdAJykgcmV0dXJuOwogCglpZiAoeD4wICYmIFRbeC0xXVt5XSAgID09ICcuJykge3d5bi0tOyB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HJpbnRmKCIlYyIsIFRbaV1bal0pOwoJCQlwcmludGYoIlxuIik7CgkJfSovCgkJcHJpbnRmKCIlZFxuIiwgd3luKTsKCX0KCXJldHVybiAwOwp9
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:51: warning: unused variable ‘foo’
prog.cpp:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout