// Arup Guha
// 3/11/2015
// Solution to UCF HS Problem: Fishy Business 2: Fish Nuggets

import java.util.*;

public class fishytoo {

	public static void main(String[] args) {

		// Get number of cases.
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in dimensions.
			int rows = stdin.nextInt();
			int cols = stdin.nextInt();

			// Add in the contribution of each row.
			int count = 0;
			for (int i=0; i<rows; i++)
				count += getCount(stdin.next());

			// Output result.
			System.out.println("Net #"+loop+": "+count+" Fish Nuggets");
		}
	}

	// Returns the number of useful squares designated in s.
	public static int getCount(String s) {

		int i = 0, result = 0;

		// Go through the row...
		while (i < s.length()) {

			// Yummy seaweed...
			if (s.charAt(i) == '~') {
				result++;
				i++;
			}

			// Yucky rocks...
			else if (s.charAt(i) == 'O' || s.charAt(i) == '#') {
				i++;
			}

			// Let's see if we get some fish.
			else {

				// Avoid out of bounds error.
				if (i+3 > s.length()) break;

				// Count the fish.
				String fish = s.substring(i, i+3);
				if (fish.equals("<><") || fish.equals("><>")) {
					result += 3;
					i += 3;
				}

				// Just go to the next slot if we didn't find a fish.
				else {
					i++;
				}
			}

		}

		// This is our useful food.
		return result;
	}
}