/* Chris Poon
   BHCSI - 2005
   Solution to Gotham, 7/15/05 Programming Contest
   A standard recursion flood fill problem.
   Squares are NOT connected diagonally.
  */

import java.io.*;
import java.util.*;
class gotham 
{

	//cityBlock is character matrix that represents the grid input.
	public static char cityBlock[][]=new char[100][100];
	public static int c, m, n;  //the # of cases, rows, columns.

	public static int vaporize(int i, int j){
		//the recursive method that food fills.
		if (i<0 || i>=m || j<0 || j>=n) return 0;
		if (cityBlock[i][j]!='o') return 0;
		
		cityBlock[i][j]='.';   //<--- prevent infinite recursion!
		int sum=1;
		sum+=vaporize(i-1, j);
		sum+=vaporize(i, j-1);
		sum+=vaporize(i, j+1);
		sum+=vaporize(i+1, j);
		return sum;
	}

	public static int activateEmitter(){
		//the driver method that finds where the
		// emitter is to begin the reaction.
		int i,j;
		int sum=0;
		for (i=0;i<m;i++){
			for (j=0;j<n; j++){
				if (cityBlock[i][j]=='X'){
					sum+=vaporize(i-1, j);
					sum+=vaporize(i, j-1);
					sum+=vaporize(i, j+1);
					sum+=vaporize(i+1, j);
				}
			}
		}
		return sum;
	}

	public static void main(String[] args) throws IOException
	{
		//reads the input and executes the driver method.
		// notice that a character matrix is best for its mutability,
		// but I initially read the lines as Strings and then convert
		// to the matrix.
		BufferedReader infile=new BufferedReader(new FileReader("gotham.in"));
		c=Integer.parseInt(infile.readLine());

		for (int x=0;x<c; x++){
			StringTokenizer strtok=new StringTokenizer(infile.readLine());
			m=Integer.parseInt(strtok.nextToken());
			n=Integer.parseInt(strtok.nextToken());
			for (int i=0; i<m; i++){
				String line=infile.readLine();
				for (int j=0;j<n; j++)
					cityBlock[i][j]=line.charAt(j);
			}
			System.out.println(activateEmitter()*5); // times 5 as spec desires.
		}
		infile.close();
	}
}
