import java.util.Scanner;
public class 黑白棋 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
for (int i = 0; i < n; i++) {
char[][] arr=new char[8][8];
for (int j = 0; j < arr.length; j++) {
String s=in.next();
for (int k = 0; k < arr.length; k++) {
arr[j][k]=s.charAt(k);
}
}
int k=in.nextInt();
int[][] bu=new int[k][3];
for (int j = 0; j < bu.length; j++) {
for (int j2 = 0; j2 < bu[0].length; j2++) {
bu[j][j2]=in.nextInt();
}
}
cal(arr,bu);
int a=0;
int b=0;
for (int j = 0; j < arr.length; j++) {
for (int j2 = 0; j2 < arr[0].length; j2++) {
if(arr[j][j2]=='*') a++;
else if(arr[j][j2]=='o') b++;
}
}
System.out.println(a+" "+b);
}
}
}
/**
*
* ........
........
....*o..
...**o..
...ooo..
........
........
........
* @param arr
* @param bu
* @return
*/
private static void cal(char[][] arr, int[][] bu) {
for (int i = 0; i < bu.length; i++) {
int x=bu[i][0];
int y=bu[i][1];
int type=bu[i][2];
char t=type==0?'*':'o';
//8个方向
findAndMod(arr,x,y,t);
}
}
private static void findAndMod(char[][] arr,int x, int y, char type) {
//8个方向
//往右
right(arr,x, y, type);
//往左
left(arr,x, y, type);
//上
shang(arr,x, y, type);
//下
xia(arr,x, y, type);
//左上
zuoshang(arr,x, y, type);
//右下
youxia(arr,x, y, type);
// 左下
zuoxia(arr,x, y, type);
//右上
youshang(arr,x, y, type);
}
private static void youshang(char[][] arr, int x, int y, char type) {
int flag=0;
int index_x=0;
int index_y=0;
for (int i = x-1,j=y+1; i>=0&&j<=7; i--,j++) {
if(arr[i][j]==type) {
flag=1;
index_x=i;
index_y=j;
break;
}
if(arr[i][j]=='.'){
break;
}
}
if(flag==1){
for (int i = x,j=y; i>=index_x&&j<=index_y; i--,j++) {
arr[i][j]=type;
}
}
}
private static void zuoxia(char[][] arr, int x, int y, char type) {
int flag=0;
int index_x=0;
int index_y=0;
for (int i = x+1,j=y-1; i<=7&&j>=0; i++,j--) {
if(arr[i][j]==type) {
flag=1;
index_x=i;
index_y=j;
break;
}
if(arr[i][j]=='.'){
break;
}
}
if(flag==1){
for (int i = x,j=y; i<=index_x&&j>=index_y; i++,j--) {
arr[i][j]=type;
}
}
}
private static void youxia(char[][] arr, int x, int y, char type) {
int flag=0;
int index_x=0;
int index_y=0;
for (int i = x+1,j=y+1; i<=7&&j<=7; i++,j++) {
if(arr[i][j]==type) {
flag=1;
index_x=i;
index_y=j;
break;
}
if(arr[i][j]=='.'){
break;
}
}
if(flag==1){
for (int i = x,j=y; i<=index_x&&j<=index_y; i++,j++) {
arr[i][j]=type;
}
}
}
private static void zuoshang(char[][] arr, int x, int y, char type) {
int flag=0;
int index_x=0;
int index_y=0;
for (int i = x-1,j=y-1; i>=0&&j>=0; i--,j--) {
if(arr[i][j]==type) {
flag=1;
index_x=i;
index_y=j;
break;
}
if(arr[i][j]=='.'){
break;
}
}
if(flag==1){
for (int i = x,j=y; i>=index_x&&j>=index_y; i--,j--) {
arr[i][j]=type;
}
}
}
private static void xia(char[][] arr, int x, int y, char type) {
int flag=0;
int index=0;
for (int i = x+1; i<=7; i++) {
if(arr[i][y]==type) {
flag=1;
index=i;
break;
}
if(arr[i][y]=='.'){
break;
}
}
if(flag==1){
for (int i = x; i<=index; i++) {
arr[i][y]=type;
}
}
}
private static void shang(char[][] arr, int x, int y, char type) {
int flag=0;
int index=0;
for (int i = x-1; i>=0; i--) {
if(arr[i][y]==type) {
flag=1;
index=i;
break;
}
if(arr[i][y]=='.'){
break;
}
}
if(flag==1){
for (int i = x; i>=index; i--) {
arr[i][y]=type;
}
}
}
private static void left(char[][] arr, int x, int y, char type) {
int flag=0;
int index=0;
for (int i = y-1; i>=0; i--) {
if(arr[x][i]==type) {
flag=1;
index=i;
break;
}
if(arr[x][i]=='.'){
break;
}
}
if(flag==1){
for (int i = y; i>=index; i--) {
arr[x][i]=type;
}
}
}
private static void right(char[][] arr, int x, int y, char type) {
int flag=0;
int index=0;
for (int i = y+1; i<=7; i++) {
if(arr[x][i]==type) {
flag=1;
index=i;
break;
}
if(arr[x][i]=='.'){
break;
}
}
if(flag==1){
for (int i = y; i <=index; i++) {
arr[x][i]=type;
}
}
}
}