#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> que,ans,res;
int n,m;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void bfs(int x,int y)
{
    while (que.size()) que.pop();
    struct note s;
    s.x=x;s.y=y;
    que.push(s);
    while (que.size()) {
        struct note cur,next;
        cur=que.front();
        que.pop();
        for (int i=0;i<4;i++) {
            int dx=cur.x+Next[i][0];
            int dy=cur.y+Next[i][1];
            if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.') {
                next.x=dx;next.y=dy;
                ans.push(cur);
                mmap[cur.x][cur.y]='#';
                que.push(next);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  res.push(cur);
                }
            }
        }
        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    bfs(i,j);
                }
            }
        }
        printf("%d\n",res.size()+ans.size());
        while (res.size()) {
            struct note cur=res.front();
            res.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  visit[505][505];
struct node
{
	int x,y;
}list[260000];
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int k = 0 ;
void doright(int i , int j )
{
   memset(list,0,sizeof(list));
   int up = 1;
   int high = 1;
   list[1].x = i ;
   list[1].y = j;
   visit[i][j] = 1;
   while(up <= high)
   {
      for(int t = 0 ;t <= 3 ;t ++)
	  {
		  int ti = list[up].x + xdd[t];
		  int tj = list[up].y + ydd[t];
		  if(str[ti][tj] == '.' && visit[ti][tj] == 0 )
		  {
                visit[ti][tj] = 1;
				high ++;
				list[high].x = ti ;
				list[high].y = tj ;
		  }

	  }
	  up++;
   }
   for(int t = high ;t > 1; t --)
   {
	  str[list[t].x][list[t].y] = '#';
      k++;
	  step[k][1] = 2 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
      k++;
	  step[k][1] = 3 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
   }

}

int main(){
   memset(visit,0,sizeof(visit));
   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }

   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;

		 }
	   }
   for(int i = 1 ;i <= n;i ++)
	   for(int j= 1;j <= m;j ++)
	   {
		if(str[i][j] == '.')
	     doright(i,j);
		 }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
   //for(int i = 1;i <= n;i ++)
	 // puts(&str[i][1]);
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int isfour(int i ,int j)
{
   int sum = 0 ;
   if(str[i][j+1] == '.' )
	   sum ++;
   if( str[i][j-1] == '.' )
	   sum ++;
   if( str[i-1][j] == '.')
	   sum++;
   if(str[i+1][j] == '.')
       sum ++;
   return sum;
}
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int main(){

   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }
   int k = 0;
   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;
		 }
	   }
   int ok1 = 1;
   while(ok1)
   {
	 int isf = 0;
     for(int i= 1;i<= n;i ++)
	 {	 for(int j = 1; j <= m; j ++)
		 {
            if(isfour(i,j) == 4 && str[i][j] == '.')
			{
               for(int ii = 0 ;ii <= 3; ii++)
			   {
			     int ti = i + xdd[ii];
				 int tj = j + ydd[ii];
				 if(str[ti][tj] == '.')
				 {
				     k ++;
					 step[k][1] = 2;
					 step[k][2] = ti;
					 step[k][3] = tj;
                     k ++;
					 step[k][1] = 3;
					 step[k][2] = ti;
					 step[k][3] = tj;
					 str[ti][tj] = '#';
				 }

			   }
			   break;

			}
		 }
		 if(isf)
			 break;
	 }
	 if(isf)
		 continue;
	 else
		 ok1 = 0 ;
   }
    ok1 = 1;
   while(ok1)
   {
	 int isf = 0;
     for(int i= 1;i<= n;i ++)
	 {	 for(int j = 1; j <= m; j ++)
		 {
            if(isfour(i,j) == 3 && str[i][j] == '.')
			{
               for(int ii = 0 ;ii <= 3; ii++)
			   {
			     int ti = i + xdd[ii];
				 int tj = j + ydd[ii];
				 if(str[ti][tj] == '.')
				 {
				     k ++;
					 step[k][1] = 2;
					 step[k][2] = ti;
					 step[k][3] = tj;
                     k ++;
					 step[k][1] = 3;
					 step[k][2] = ti;
					 step[k][3] = tj;
					 str[ti][tj] = '#';
				 }
			   }
			   break;

			}
		 }
		 if(isf)
			 break;
	 }
	 if(isf)
		 continue;
	 else
		 ok1 = 0 ;
   }
   ok1 = 1;
   while(ok1)
   {
	 int isf = 0;
     for(int i= 1;i<= n;i ++)
	 {	 for(int j = 1; j <= m; j ++)
		 {
            if(isfour(i,j) == 2 && str[i][j] == '.')
			{
               for(int ii = 0 ;ii <= 3; ii++)
			   {
			     int ti = i + xdd[ii];
				 int tj = j + ydd[ii];
				 if(str[ti][tj] == '.')
				 {
				     k ++;
					 step[k][1] = 2;
					 step[k][2] = ti;
					 step[k][3] = tj;
                     k ++;
					 step[k][1] = 3;
					 step[k][2] = ti;
					 step[k][3] = tj;
					 str[ti][tj] = '#';
				 }
			   }
			   break;

			}
		 }
		 if(isf)
			 break;
	 }
	 if(isf)
		 continue;
	 else
		 ok1 = 0 ;
   }
    ok1 = 1;
   while(ok1)
   {
	 int isf = 0;
     for(int i= 1;i<= n;i ++)
	 {	 for(int j = 1; j <= m; j ++)
		 {
            if(isfour(i,j) == 1 && str[i][j] == '.')
			{
               for(int ii = 0 ;ii <= 3; ii++)
			   {
			     int ti = i + xdd[ii];
				 int tj = j + ydd[ii];
				 if(str[ti][tj] == '.')
				 {
				     k ++;
					 step[k][1] = 2;
					 step[k][2] = ti;
					 step[k][3] = tj;
                     k ++;
					 step[k][1] = 3;
					 step[k][2] = ti;
					 step[k][3] = tj;
					 str[ti][tj] = '#';
				 }
			   }
			   break;

			}
		 }
		 if(isf)
			 break;
	 }
	 if(isf)
		 continue;
	 else
		 ok1 = 0 ;
   }
   printf("%d\n",k);
   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  map[505][505];
int isfour(int i ,int j)
{
   int sum = 0 ;
   if(str[i][j+1] == '.' )
	   sum ++;
   if( str[i][j-1] == '.' )
	   sum ++;
   if( str[i-1][j] == '.')
	   sum++;
   if(str[i+1][j] == '.')
       sum ++;
   return sum;
}
int cando(int i ,int j )
{
      if(str[i][j+1] == '.' && str[i+1][j] == '.')
		  return 1;
	  if(str[i][j+1] == '.' && str[i-1][j] == '.')
		  return 1;
      if(str[i][j-1] == '.' && str[i+1][j] == '.')
		  return 1;
	  if(str[i][j-1] == '.' && str[i-1][j] == '.')
		  return 1;
	  return 0;

}
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int main(){

   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }
   int k = 0;
   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;
		   map[i][j] = isfour(i,j);

		 }
	   }
   int bigok = 1;
   while(bigok)
   {
	 bigok = 0 ;
     for(int i =1 ; i <= n;i ++)
	 {  for(int j = 1;j <= m; j++)
		{
		   if(str[i][j] == '.' && map[i][j] == 1)
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  str[i][j] = '#';
			  bigok = 1;
			  for(int ii = 0; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
            break;
		   }
		}
		if(bigok)
			break;
	 }
	 if(!bigok)
	   for(int i = 1;i <= n;i ++)
	   { for(int j = 1;j <= m; j ++)
		 {
		   if(str[i][j] == '.' && map[i][j] == 2 && cando(i,j))
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  bigok = 1;
			  str[i][j] = '#';
			  for(int ii = 0; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
			  break;
		   }
		 }
		 if(bigok)
			 break;
	   }

   }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int isfour(int i ,int j)
{
	int sum = 0 ;
	if(str[i][j+1] != '.' )
		sum ++;
	if( str[i][j-1] != '.' )
		sum ++;
	if( str[i-1][j] != '.')
		sum++;
	if(str[i+1][j] != '.')
		sum ++;
	return sum;
}
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int main(){

	//freopen("/home/plac/problem/input.txt","r",stdin);
	//freopen("/home/plac/problem/output.txt","w",stdout);
	int n ,m ;
	scanf("%d %d",&n,&m);
	for(int i = 1;i <= n;i ++)
	{
		scanf("%s",&str[i][1]);
	}
	int k = 0;
	for(int i= 1;i <= n;i ++)
		for(int j = 1; j <= m;j ++)
		{
			if(str[i][j] == '.')
			{
				k++;
				step[k][1] = 1;
				step[k][2] = i;
				step[k][3] = j;
			}
		}
	int bigok = 1;
	while(bigok)
	{
		bigok = 0 ;
		int ok1 = 1;
		while(ok1)
		{
			int isf = 0;
			for(int i= 1;i<= n;i ++)
			{	 for(int j = 1; j <= m; j ++)
				{
					if( str[i][j] == '.' && isfour(i,j) == 3)
					{
						k ++;
						step[k][1] = 2;
						step[k][2] = i;
						step[k][3] = j;
						k ++;
						step[k][1] = 3;
						step[k][2] = i;
						step[k][3] = j;
						str[i][j] = '#';
						isf = 1 ;
						bigok = 1;
					}

				}
			}
			if(isf)
				continue;
			else
				ok1 = 0 ;
		}
		ok1 = 1;
		while(ok1)
		{
			int isf = 0;
			for(int i= 1;i<= n;i ++)
			{	 for(int j = 1; j <= m; j ++)
				{
					if( str[i][j] == '.' && isfour(i,j) == 2)
					{
						k ++;
						step[k][1] = 2;
						step[k][2] = i;
						step[k][3] = j;
						k ++;
						step[k][1] = 3;
						step[k][2] = i;
						step[k][3] = j;
						str[i][j] = '#';
						isf = 1  ;
						bigok = 1;
					}

				}
			}

			if(isf)
				continue;
			else
				ok1 = 0 ;
		}
		ok1 = 1;
		while(ok1)
		{
			int isf = 0;
			for(int i= 1;i<= n;i ++)
			{	 for(int j = 1; j <= m; j ++)
				{
					if( str[i][j] == '.' && isfour(i,j) == 1)
					{
						k ++;
						step[k][1] = 2;
						step[k][2] = i;
						step[k][3] = j;
						k ++;
						step[k][1] = 3;
						step[k][2] = i;
						step[k][3] = j;
						str[i][j] = '#';
						isf = 1  ;
						bigok = 1;
					}

				}
			}
			if(isf)
				continue;
			else
				ok1 = 0 ;
		}
	}
	printf("%d\n",k);

	for(int i =1 ;i <= k ;i ++)
	{
		if(step[i][1] == 1)
			printf("B ");
		else if(step[i][1] == 2)
			printf("D ");
		else printf("R ");
		printf("%d %d\n",step[i][2],step[i][3]);
	}
	return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  visit[505][505];
struct node
{
	int x,y;
}list[300000];
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int k = 0 ;
void doright(int i , int j )
{
   memset(list,0,sizeof(list));
   int up = 1;
   int high = 1;
   list[1].x = i ;
   list[1].y = j;
   visit[i][j] = 1;
   while(up <= high)
   {
      for(int t = 0 ;t <= 3 ;t ++)
	  {
		  int ti = list[up].x + xdd[t];
		  int tj = list[up].y + ydd[t];
		  if(str[ti][tj] == '.' && visit[ti][tj] == 0 )
		  {
                visit[ti][tj] = 1;
				high ++;
				list[high].x = ti ;
				list[high].y = tj ;
		  }

	  }
	  up++;
   }
   for(int t = high ;t > 1; t --)
   {
	  str[list[t].x][list[t].y] = '#';
      k++;
	  step[k][1] = 2 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
      k++;
	  step[k][1] = 3 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
   }

}

int main(){
   memset(visit,0,sizeof(visit));
   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }

   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;

		 }
	   }
   for(int i = 1 ;i <= n;i ++)
	   for(int j= 1;j <= m;j ++)
	   {
		if(str[i][j] == '.')
	     doright(i,j);
		 }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
   //for(int i = 1;i <= n;i ++)
	 // puts(&str[i][1]);
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  visit[505][505];
struct node
{
	int x,y;
}list[30000];
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int k = 0 ;
void doright(int i , int j )
{
   memset(list,0,sizeof(list));
   int up = 1;
   int high = 1;
   list[1].x = i ;
   list[1].y = j;
   visit[i][j] = 1;
   while(up <= high)
   {
      for(int t = 0 ;t <= 3 ;t ++)
	  {
		  int ti = list[up].x + xdd[t];
		  int tj = list[up].y + ydd[t];
		  if(str[ti][tj] == '.' && visit[ti][tj] == 0 )
		  {
                visit[ti][tj] = 1;
				high ++;
				list[high].x = ti ;
				list[high].y = tj ;
		  }

	  }
	  up++;
   }
   for(int t = high ;t > 1; t --)
   {
	  str[list[t].x][list[t].y] = '#';
      k++;
	  step[k][1] = 2 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
      k++;
	  step[k][1] = 3 ;
	  step[k][2] = list[t].x;
	  step[k][3] = list[t].y;
   }

}

int main(){
   memset(visit,0,sizeof(visit));
   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }

   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;

		 }
	   }
   for(int i = 1 ;i <= n;i ++)
	   for(int j= 1;j <= m;j ++)
	   {
		if(str[i][j] == '.')
	     doright(i,j);

	   }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
   //for(int i = 1;i <= n;i ++)
	 // puts(&str[i][1]);
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  map[505][505];
int isfour(int i ,int j)
{
   int sum = 0 ;
   if(str[i][j+1] == '.' )
	   sum ++;
   if( str[i][j-1] == '.' )
	   sum ++;
   if( str[i-1][j] == '.')
	   sum++;
   if(str[i+1][j] == '.')
       sum ++;
   return sum;
}
int cando(int i ,int j )
{
      if(str[i][j+1] == '.' && str[i+1][j] == '.')
		  return 1;
	  if(str[i][j+1] == '.' && str[i-1][j] == '.')
		  return 1;
      if(str[i][j-1] == '.' && str[i+1][j] == '.')
		  return 1;
	  if(str[i][j-1] == '.' && str[i-1][j] == '.')
		  return 1;
	  return 0;

}
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int main(){

   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
	  if(n == 21  && m == 23)
      puts(&str[i][1]);
   }

   int k = 0;
   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;
		   map[i][j] = isfour(i,j);

		 }
	   }
   int bigok = 1;
   while(bigok)
   {
	 bigok = 0 ;
     for(int i =1 ; i <= n;i ++)
	 {  for(int j = 1;j <= m; j++)
		{
		   if(str[i][j] == '.' && map[i][j] == 1)
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  str[i][j] = '#';
			  bigok = 1;
			  for(int ii = 0; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
            break;
		   }
		}
		if(bigok)
			break;
	 }
	 if(!bigok)
	   for(int i = 1;i <= n;i ++)
	   { for(int j = 1;j <= m; j ++)
		 {
		   if(str[i][j] == '.' && map[i][j] == 2 && cando(i,j))
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  bigok = 1;
			  str[i][j] = '#';
			  for(int ii = 0; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
			  break;
		   }
		 }
		 if(bigok)
			 break;
	   }

   }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
return 0 ;
}


// File Name: d.c
// Author: darkdream
// Created Time: 2013年07月18日 星期四 20时43分56秒

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
char str[505][505];
int  step[1000005][4];
int  map[505][505];
int isfour(int i ,int j)
{
   int sum = 0 ;
   if(str[i][j+1] != '.' )
	   sum ++;
   if( str[i][j-1] != '.' )
	   sum ++;
   if( str[i-1][j] != '.')
	   sum++;
   if(str[i+1][j] != '.')
       sum ++;
   return sum;
}
int xdd[] = {0,0,1,-1};
int ydd[] = {1,-1,0,0};
int main(){

   //freopen("/home/plac/problem/input.txt","r",stdin);
   //freopen("/home/plac/problem/output.txt","w",stdout);
   int n ,m ;
   scanf("%d %d",&n,&m);
   for(int i = 1;i <= n;i ++)
   {
      scanf("%s",&str[i][1]);
   }
   int k = 0;
   for(int i= 1;i <= n;i ++)
	   for(int j = 1; j <= m;j ++)
	   {
	     if(str[i][j] == '.')
		 {
		   k++;
		   step[k][1] = 1;
		   step[k][2] = i;
		   step[k][3] = j;
		   map[i][j] = isfour(i,j);

		 }
	   }
   int bigok = 1;
   while(bigok)
   {
	 bigok = 0 ;
     for(int i =1 ; i <= n;i ++)
        for(int j = 1;j <= m; j++)
		{
		   if(str[i][j] == '.' && map[i][j] == 3)
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  str[i][j] = '#';
			  bigok = 1;
			  for(int ii = 1; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
		   }
		}
	 if(!bigok)
	   for(int i = 1;i <= n;i ++)
	     for(int j = 1;j <= m; j ++)
		 {
		   if(str[i][j] == '.' && map[i][j] == 2)
		   {
		      k ++;
			  step[k][1] = 2;
			  step[k][2] = i;
			  step[k][3] = j;
		      k ++;
			  step[k][1] = 3;
			  step[k][2] = i;
			  step[k][3] = j;
			  bigok = 1;
			  str[i][j] = '#';
			  for(int ii = 1; ii <= 3; ii ++)
			  {
			    int ti = i + xdd[ii];
				int tj = j + ydd[ii];
				map[ti][tj] --;
			  }
		   }

		 }

   }
   printf("%d\n",k);

   for(int i =1 ;i <= k ;i ++)
   {
     if(step[i][1] == 1)
		 printf("B ");
	 else if(step[i][1] == 2)
		 printf("D ");
	 else printf("R ");
	 printf("%d %d\n",step[i][2],step[i][3]);
   }
return 0 ;
}


#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
     int t;
    cin>>t;
    int ans[t];
    for(int i=0;i<t;i++)
    {int a,b,c;

    cin>>a>>b>>c;
    int p=a*b*c;
  int  s=a+b+c;
    if(a>=4 && b>=4 && c>=4)ans[i]=7;
        else if(a==0 && b==0 && c==0)ans[i]=0;
        else if(p==0 && b*c==0)ans[i]=1;
        else if(s==2)ans[i]=2;
        else if(p==1|| p==0||a==1&&b==1||a==1&&c==1)ans[i]=3;
        else if(a==1||b==1||c==1)ans[i]=4;
        else if(a==2||b==2||c==2)ans[i]=5;
        else ans[i]=6;

    }
    for(int i=0;i<t;i++)
    cout<<ans[i]<<endl;

}


#include<stdio.h>
#include<stdlib.h>
int verificarNum(int num[], int i);
int main(){
    int times=0, num[3], resul=0, i=0, j=0, aux=0, f=0;
    scanf("%d", &times);
    while(times--){
        resul=0;
        scanf("%d %d %d", &num[0], &num[1], &num[2]);
        for(i=0; i<3; i++)
            if(num[i]>4)
                num[i]=4;
        for(i=0; i<3; i++){
            for(j=i+1; j<3; j++){
                if(num[j]<num[i]){
                    aux=num[i];
                    num[i]=num[j];
                    num[j]=aux;
                }
            }
        }
        //for(i=0; i<3; i++)
        //    printf("%d ", num[i]);
        for(i=0; i<7; i++){
            if(num[0]==0){
                resul+=verificarNum(num, i);
                break;
            }else{
                if(num[0]!=0){
                    resul++;
                    num[0]--;
                }
                if(i==1 && num[1]!=0)
                    num[1]--;
                if(i==2 && num[2]!=0)
                    num[2]--;
                if(i==3){
                    if(num[2]!=0)
                        num[2]--;
                    if(num[1]!=0)
                        num[1]--;
                }
            }
        }
        printf("%d \n", resul);
    }

    return 0;
}
int verificarNum(int num[], int i){
    if(num[1]==0 && num[2]!=0)
        return 1;
    if(num[1]<2 && num[1]!=0){
        if(i==2 &&  num[2]-1>=2)
            return 3;
        return 2;
    }
    if(num[2]>=2 && num[1]>=2)
        return 3;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){

    int num=0,a=0, b=0, c=0, f=0, resultado=0, menor=0, mayor=0;
    scanf("%d", &num);
    while(num--){
       resultado=0;
        scanf("%d %d %d", &a, &b, &c);
        /*if(a>4)
            a=4;
        if(b>4)
            b=4;
        if(c>4)
            c=4;*/
           // printf("%d, %d, %d", a, b ,c);

        if(a==b && b==c && a==c){
            if(a==1)
                printf("3\n");
            else if(a==2)
                printf("4\n");
            else if(a==3)
                printf("6\n");
            else if(a==4)
                printf("7\n");
            else if(a==0)
                 printf("0\n");
        }else{

            menor=a;
            f=0;
            if (b<a && b<=c){
                menor=b;
                f=1;
            }
            else if(c<a && c<=b ){
                menor=c;
                f=3;
            }
            resultado+=menor;
            if(f==0){
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(f==1){
                if(a==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(f==2){
                if(a==1 || b==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else
                resultado+=3;

            /*menor=a;
            if (b<a && b<c)
                menor=b;
            else if (c<a && c<b )
                menor=c;
            //menor=1
            mayor=a;
            if (b>a && b>c)
                mayor=b;//2
            else if (c>a && c>b )
                mayor=c;
            //mayor=2
            mayor=(mayor-menor)+1;
            //mayor=2-1+1=2

            if(mayor>1 && b>1){
                resultado=menor;
                resultado+=2;
                printf("%d\n", resultado);
                break;
            }
            else{
                resultado=menor;
                resultado+=4;
                printf("%d\n", resultado);
                break;
            }
            if(a<b && a<c){
                b-=a;
                c-=a;
                resultado+=a;
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(b<a && b<c){
                a-=b;
                c-=b;
                resultado+=b;
                if(a==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(c<a && c<b){
                a-=c;
                b-=c;
                resultado+=c;
                if(a==1 || b==1)
                    resultado+=2;
                else
                    resultado+=3;
            }*/
            printf("%d\n", resultado);
        }

    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int verificarNum(int num[], int i);
int main(){
    int times=0, num[3], resul=0, i=0, j=0, aux=0, f=0;
    scanf("%d", &times);
    while(times--){
        resul=0;
        scanf("%d %d %d", &num[0], &num[1], &num[2]);
        for(i=0; i<3; i++)
            if(num[i]>4)
                num[i]=4;
        for(i=0; i<3; i++){
            for(j=i+1; j<3; j++){
                if(num[j]<num[i]){
                    aux=num[i];
                    num[i]=num[j];
                    num[j]=aux;
                }
            }
        }
        //for(i=0; i<3; i++)
        //    printf("%d ", num[i]);
        for(i=0; i<7; i++){
            if(num[0]==0){
                resul+=verificarNum(num, i);
                break;
            }else{
                if(num[0]!=0){
                    resul++;
                    num[0]--;
                }
                if(i==1 && num[1]!=0)
                    num[1]--;
                if(i==2 && num[2]!=0)
                    num[2]--;
                if(i==3){
                    if(num[2]!=0)
                        num[2]--;
                    if(num[1]!=0)
                        num[1]--;
                }
            }
        }
        printf("%d \n", resul);
    }

    return 0;
}
int verificarNum(int num[], int i){
    if(num[1]==0 && num[2]!=0)
        return 1;
    if(num[1]<2 && num[1]!=0){
        if(i==2)
            return 3;
        return 2;
    }
    if(num[2]>=2 && num[1]>=2)
        return 3;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int verificarNum(int num[], int i);
int main(){
    int times=0, num[3], resul=0, i=0, j=0, aux=0, f=0;
    scanf("%d", &times);
    while(times--){
        resul=0;
        scanf("%d %d %d", &num[0], &num[1], &num[2]);
        for(i=0; i<3; i++)
            if(num[i]>4)
                num[i]=4;
        for(i=0; i<3; i++){
            for(j=i+1; j<3; j++){
                if(num[j]<num[i]){
                    aux=num[i];
                    num[i]=num[j];
                    num[j]=aux;
                }
            }
        }
        //for(i=0; i<3; i++)
        //    printf("%d ", num[i]);
        for(i=0; i<7; i++){
            if(num[0]==0){
                resul+=verificarNum(num, i);
                break;
            }else{
                if(num[0]!=0){
                    resul++;
                    num[0]--;
                }
                if(i==1 && num[1]!=0)
                    num[1]--;
                if(i==2 && num[2]!=0)
                    num[2]--;
                if(i==3){
                    if(num[2]!=0)
                        num[2]--;
                    if(num[1]!=0)
                        num[1]--;
                }
            }
        }
        printf("%d \n", resul);
    }

    return 0;
}
int verificarNum(int num[], int i){
    if(num[1]==0 && num[2]!=0)
        return 1;
    if(num[1]<2 && num[1]!=0){
        if(i==2)
            return 3;
        return 2;
    }
    if(num[2]>=2 && num[1]>=2)
        return 3;

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int verificarNum(int num[], int i);
int main(){
    int times=0, num[3], resul=0, i=0, j=0, aux=0, f=0;
    scanf("%d", &times);
    while(times--){
        resul=0;
        scanf("%d %d %d", &num[0], &num[1], &num[2]);
        for(i=0; i<3; i++)
            if(num[i]>4)
                num[i]=4;
        for(i=0; i<3; i++){
            for(j=i+1; j<3; j++){
                if(num[j]<num[i]){
                    aux=num[i];
                    num[i]=num[j];
                    num[j]=aux;
                }
            }
        }
        //for(i=0; i<3; i++)
        //    printf("%d ", num[i]);
        for(i=0; i<7; i++){
            if(num[0]==0){
                resul+=verificarNum(num, i);
                break;
            }else{
                if(num[0]!=0){
                    resul++;
                    num[0]--;
                }
                if(i==1 && num[1]!=0)
                    num[1]--;
                if(i==2 && num[2]!=0)
                    num[2]--;
                if(i==3){
                    if(num[2]!=0)
                        num[2]--;
                    if(num[1]!=0)
                        num[1]--;
                }
            }
        }
        printf("%d \n", resul);
    }

    return 0;
}
int verificarNum(int num[], int i){
    if(num[1]==0 && num[2]!=0)
        return 1;
    if(num[1]<2 && num[1]!=0){
        if(i==2)
            return 3;
        return 2;
    }
    if(num[2]>=2 && num[1]>=2)
        return 3;
}


#include<stdio.h>
#include<stdlib.h>

int main(){

    int num=0,a=0, b=0, c=0, f=0, resultado=0, menor=0, mayor=0;
    scanf("%d", &num);
    while(num--){
       resultado=0;
        scanf("%d %d %d", &a, &b, &c);
        if(a>4)
            a=4;
        if(b>4)
            b=4;
        if(c>4)
            c=4;
           // printf("%d, %d, %d", a, b ,c);

        if(a==b && b==c && a==c){
            if(a==1)
                printf("3\n");
            else if(a==2)
                printf("4\n");
            else if(a==3)
                printf("6\n");
            else if(a==4)
                printf("7\n");
            else if(a==0)
                 printf("0\n");
        }else{

            menor=a;
            f=0;
            if (b<a && b<c){
                menor=b;
                f=1;
            }
            else if (c<a && c<b ){
                menor=c;
                f=3;
            }
            resultado+=menor;
            if(f==0)
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;

            /*menor=a;
            if (b<a && b<c)
                menor=b;
            else if (c<a && c<b )
                menor=c;
            //menor=1
            mayor=a;
            if (b>a && b>c)
                mayor=b;//2
            else if (c>a && c>b )
                mayor=c;
            //mayor=2
            mayor=(mayor-menor)+1;
            //mayor=2-1+1=2

            if(mayor>1 && b>1){
                resultado=menor;
                resultado+=2;
                printf("%d\n", resultado);
                break;
            }
            else{
                resultado=menor;
                resultado+=4;
                printf("%d\n", resultado);
                break;
            }
            if(a<b && a<c){
                b-=a;
                c-=a;
                resultado+=a;
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(b<a && b<c){
                a-=b;
                c-=b;
                resultado+=b;
                if(a==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(c<a && c<b){
                a-=c;
                b-=c;
                resultado+=c;
                if(a==1 || b==1)
                    resultado+=2;
                else
                    resultado+=3;
            }*/
            printf("%d\n", resultado);
        }

    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){

    int num=0,a=0, b=0, c=0, f=0, resultado=0, menor=0, mayor=0;
    scanf("%d", &num);
    while(num--){
       resultado=0;
        scanf("%d %d %d", &a, &b, &c);
        if(a>4)
            a=4;
        if(b>4)
            b=4;
        if(c>4)
            c=4;
           // printf("%d, %d, %d", a, b ,c);

        if(a==b && b==c && a==c){
            if(a==1)
                printf("3\n");
            else if(a==2)
                printf("4\n");
            else if(a==3)
                printf("6\n");
            else if(a==4)
                printf("7\n");
            else if(a==0)
                 printf("0\n");
        }else{

            menor=a;
            f=0;
            if (b<a && b<c){
                menor=b;
                f=1;
            }
            else if (c<a && c<b ){
                menor=c;
                f=3;
            }
            resultado+=menor;
            if(f==0){
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(f==1){
                if(a==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(f==2){
                if(a==1 || b==1)
                    resultado+=2;
                else
                    resultado+=3;
            }

            /*menor=a;
            if (b<a && b<c)
                menor=b;
            else if (c<a && c<b )
                menor=c;
            //menor=1
            mayor=a;
            if (b>a && b>c)
                mayor=b;//2
            else if (c>a && c>b )
                mayor=c;
            //mayor=2
            mayor=(mayor-menor)+1;
            //mayor=2-1+1=2

            if(mayor>1 && b>1){
                resultado=menor;
                resultado+=2;
                printf("%d\n", resultado);
                break;
            }
            else{
                resultado=menor;
                resultado+=4;
                printf("%d\n", resultado);
                break;
            }
            if(a<b && a<c){
                b-=a;
                c-=a;
                resultado+=a;
                if(b==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(b<a && b<c){
                a-=b;
                c-=b;
                resultado+=b;
                if(a==1 || c==1)
                    resultado+=2;
                else
                    resultado+=3;
            }else if(c<a && c<b){
                a-=c;
                b-=c;
                resultado+=c;
                if(a==1 || b==1)
                    resultado+=2;
                else
                    resultado+=3;
            }*/
            printf("%d\n", resultado);
        }

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c,count=0,flag=0;
		cin>>a>>b>>c;
		if(a==0 && b==0 && c==0)
		{
			cout<<0<<"\n";
		}
		else
		{
		  	if(a>0)
		  	{
		  		a=a-1;
		  		count=count+1;
		    }
		    if(b>0)
		  	{
		  		b=b-1;
		  		count=count+1;
		    }
		    if(c>0)
		  	{
		  		c=c-1;
		  		count=count+1;
		    }
				if(a>0 && b>0 && !(c>b&&c>a) )
			{
				a=a-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(c>0 && b>0 && !(a>b&&a>c))
			{
				c=c-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(c>0 && a>0 && !(b>c&&b>a))
			{
				a=a-1;
		  		c=c-1;
		  		count=count+1;
			}

			if(a>0 && b>0 && c>0)
		  	{
		  		count=count+1;
			}
			cout<<count<<"\n";
		}
	}
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int aa[3],count=0,a,b,c,i;
		for(i=0;i<3;i++)
		{
			cin>>aa[i];
			if(aa[i]>0)
		  	{
		  		aa[i]=aa[i]-1;
		  		count=count+1;
		    }
		}
		sort(aa,aa+3);
		a=aa[0];
		b=aa[1];
		c=aa[2];
		if(a==0 && b==0 && c==0)
		{
			cout<<count<<"\n";
		}
		else
		{
		    if(c>0 && b>0 )
			{
				c=c-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(c>0 && a>0 )
			{
				a=a-1;
		  		c=c-1;
		  	    count=count+1;
			}
				if(a>0 && b>0 )
			{
				a=a-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(a>0 && b>0 && c>0)
		  	{
		  		count=count+1;
			}
			cout<<count<<"\n";
		}
	}
}


#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c,count=0,flag=0;
		cin>>a>>b>>c;
		if(a==0 && b==0 && c==0)
		{
			cout<<0<<"\n";
		}
		else
		{
		  	if(a>0 && b>0 && c>0)
		  	{
		  		a=a-1;
		  		b=b-1;
		  		c=c-1;
		  		count=3;
			}
			if(a>0 && b>0)
			{
				a=a-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(c>0 && b>0)
			{
				c=c-1;
		  		b=b-1;
		  		count=count+1;
			}
			if(c>0 && a>0)
			{
				a=a-1;
		  		c=c-1;
		  		count=count+1;
			}
			if(a>0 && b>0 && c>0)
		  	{
		  		count=count+1;
			}
			cout<<count<<"\n";
		}
	}
}


#include<bits/stdc++.h>

using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input Output ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a,pll b){ if(a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

/*** BitWise Operations
bool getBit (ll num, ll pos) { return num & (1 << pos); } // get bit right -> left
ll setBit (ll num, ll pos) { return num | (1 << pos); }
ll chearBit (ll num, ll pos) { ll mask = ~(1 << pos); return num & mask; }
ll updateBit (ll num, ll pos, bool bit1or0) { ll value = bit1or0 ? 1 : 0; ll mask = ~(1 << pos); return (num & mask) | (value << pos); }
 ***/

/*** Grids ***/
int drx[8] = {-2,-2,-1,-1,1,1,2,2};
int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
int dirx[4] = { -1, 0, 1, 0 };
int diry[4] = { 0, -1, 0, 1 };

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
 ***/
template <class T> inline T gcd(T a,T b){if(b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a,T b){return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll ans = 1;while(p--) ans *= b; return ans;}

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

ll call(ll a, ll b, ll c)
{
    ll ans = 0;
    if(a > 0) { a--; ans++; }
    if(b > 0) { b--; ans++; }
    if(c > 0) { c--; ans++; }
    if(a > 0 && b > 0) { a--; b--; ans++; }
    if(a > 0 && c > 0) { a--; c--; ans++; }
    if(b > 0 && c > 0) { b--; c--; ans++; }
    if(a > 0 && b > 0 && c > 0) ans++;
    return ans;
}

int main() {

#ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
    //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
#endif

    ll n, m, num, tc, t = 1;
    sc1(tc);
    while (tc--) {
        ll a, b, c;
        cin >> a >> b >> c;

        ll ans = 0;
        ans = max(ans, call(a, b, c));

        pf1(ans);
    }

#ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
#endif

}


#include<bits/stdc++.h>

using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input Output ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a,pll b){ if(a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

/*** BitWise Operations
bool getBit (ll num, ll pos) { return num & (1 << pos); } // get bit right -> left
ll setBit (ll num, ll pos) { return num | (1 << pos); }
ll chearBit (ll num, ll pos) { ll mask = ~(1 << pos); return num & mask; }
ll updateBit (ll num, ll pos, bool bit1or0) { ll value = bit1or0 ? 1 : 0; ll mask = ~(1 << pos); return (num & mask) | (value << pos); }
 ***/

/*** Grids ***/
int drx[8] = {-2,-2,-1,-1,1,1,2,2};
int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
int dirx[4] = { -1, 0, 1, 0 };
int diry[4] = { 0, -1, 0, 1 };

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
 ***/
template <class T> inline T gcd(T a,T b){if(b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a,T b){return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll ans = 1;while(p--) ans *= b; return ans;}

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

ll call(ll a, ll b, ll c)
{
    ll ans = 0;
    if(a > 0) { a--; ans++; }
    if(b > 0) { b--; ans++; }
    if(c > 0) { c--; ans++; }
    if(a > 0 && b > 0) { a--; b--; ans++; }
    if(a > 0 && c > 0) { a--; c--; ans++; }
    if(b > 0 && c > 0) { b--; c--; ans++; }
    if(a > 0 && b > 0 && c > 0) ans++;
    return ans;
}

int main() {

#ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
    //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
#endif

    ll n, m, num, tc, t = 1;
    sc1(tc);
    while (tc--) {
        ll a, b, c;
        cin >> a >> b >> c;

        ll ans = 0;
        ans = max(ans, call(a, b, c));
        ans = max(ans, call(a, c, b));
        ans = max(ans, call(b, a, c));
        ans = max(ans, call(b, c, a));
        ans = max(ans, call(c, a, b));
        ans = max(ans, call(c, b, a));

        pf1(ans);
    }

}


#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>

using namespace std;
typedef long long ll;

const int N=200000+10;
const int M=100000+10;

int main()
{
    int n;
    cin>>n;
    vector <int> v(3);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>v[j];
        }
        sort(v.begin(),v.end());
        int suma=0;
        if(v[0]>3)
        {
            suma=7;
        }
        else if(v[0]==3)
            suma=6;
        else if(v[0]==2)
            suma=5;
        else if(v[0]==1)
        {
            if(v[1]>=2)
                suma=4;
            else
                suma=3;
        }
        else
        {
            if(v[1]>=1)
                suma=2;
            else if(v[2]>=1)
                suma=1;
        }
        cout<<suma<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input Output ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a,pll b){ if(a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

/*** BitWise Operations
bool getBit (ll num, ll pos) { return num & (1 << pos); } // get bit right -> left
ll setBit (ll num, ll pos) { return num | (1 << pos); }
ll chearBit (ll num, ll pos) { ll mask = ~(1 << pos); return num & mask; }
ll updateBit (ll num, ll pos, bool bit1or0) { ll value = bit1or0 ? 1 : 0; ll mask = ~(1 << pos); return (num & mask) | (value << pos); }
 ***/

/*** Grids ***/
int drx[8] = {-2,-2,-1,-1,1,1,2,2};
int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
int dirx[4] = { -1, 0, 1, 0 };
int diry[4] = { 0, -1, 0, 1 };

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
 ***/
template <class T> inline T gcd(T a,T b){if(b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a,T b){return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll ans = 1;while(p--) ans *= b; return ans;}

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

ll call(ll a, ll b, ll c)
{
    ll ans = 0;
    if(a > 0) { a--; ans++; }
    if(b > 0) { b--; ans++; }
    if(c > 0) { c--; ans++; }
    if(a > 0 && b > 0) { a--; b--; ans++; }
    if(a > 0 && c > 0) { a--; c--; ans++; }
    if(b > 0 && c > 0) { b--; c--; ans++; }
    if(a > 0 && b > 0 && c > 0) ans++;
    return ans;
}

int main() {

#ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
    //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
#endif

    ll n, m, num, tc, t = 1;
    sc1(tc);
    vector <int> v(3);
    while (tc--) {
        ll a, b, c;
        cin >> v[0]>>v[1]>>v[2];
        sort(v.begin(),v.end());
        a=v[0];b=v[1];c=v[2];

        ll ans = 0;
        ans = max(ans, call(a, b, c));

        pf1(ans);
    }

}


#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>

using namespace std;
typedef long long ll;

const int N=200000+10;
const int M=100000+10;

int main()
{
    int n;
    cin>>n;
    vector <int> v(3);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>v[j];
        }
        sort(v.begin(),v.end());
        int suma=0;
        if(v[0]>3)
        {
            suma=7;
        }
        else if(v[0]==3)
            suma=6;
        else if(v[0]==2){
            if(v[1]>2)
                suma=5;
            else
                suma=4;
        }

        else if(v[0]==1)
        {
            if(v[1]>=2)
                suma=4;
            else
                suma=3;
        }
        else
        {
            if(v[1]>=1)
                suma=2;
            else if(v[2]>=1)
                suma=1;
        }
        cout<<suma<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		int m2=max(a,max(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c-m-m2!=1) ans=4;
			if(m==1 && a+b+c-m-m2==1) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c-m-m2>=2) ans=3;
				if(a+b+c-m-m2==0) ans=1;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c>=5) ans=4;
			if(m==1 && a+b+c<5) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c>=4) ans=3;
				if(a+b+c==1) ans=1;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c>=5) ans=4;
			if(m==1 && a+b+c<5) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c>=4) ans=3;
				if(a+b+c==1) ans=2;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		int m2=max(a,max(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c-m-m2!=1) ans=4;
			if(m==1 && a+b+c<-m-m2==1) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c-m-m2>=2) ans=3;
				if(a+b+c-m-m2==0) ans=1;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c>=5) ans=4;
			if(m==1 && a+b+c<5) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c>=4) ans=3;
				if(a+b+c==1) ans=2;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int ans;
		int m=min(a,min(b,c));
		int m2=max(a,max(b,c));
		if(m>=4) ans=7;
		else
		{
			if(m==3) ans=6;
			if(m==2 && a+b+c>6) ans=5;
			if(m==2 && a+b+c==6) ans=4;
			if(m==1 && a+b+c-m-m2!=1) ans=4;
			if(m==1 && a+b+c<-m-m2==1) ans=3;
			if(m==0)
			{
				ans=2;
				if(a+b+c-m-m2>=2) ans=3;
				if(a+b+c-m-m2==0) ans=1;
				if(a+b+c==0) ans=0;
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int t;
	int a[3];
	int max ,min,nmax,nmin;
	scanf("%d", &t);
	while (t) {
		scanf("%d%d%d", &a[0], &a[1], &a[2]);
		nmax = 0;
		nmin = 0;
		max = a[0];
		min = a[0];
		for (int i = 1; i < 3; i++) {
			if (max < a[i]) {
				max = a[i];
			}

			if (min > a[i]) {
				min = a[i];
			}
		}
		for (int i = 0; i < 3; i++) {
			if (a[i] == max)
				nmax++;
			if (a[i] == min)
				nmin++;
		}
		if (max >= 1 && min == 0 && nmax == 1) {
			printf("1\n");
		}
		else if (max == 0)
			printf("0\n");
		else if (max >= 1 && min == 0 && nmin == 1)
			printf("2\n");
		else if ((max >= 2 && min == 1 && nmin == 2) || (max >= 2 && min == 0 && nmin == 1) || (max == 1 && nmax == 3))
			printf("3\n");
		else if ((max >= 2 && min == 1 && nmin == 1) || (max == 2 && nmax == 3))
			printf("4\n");
		else if (max >= 3 && min == 2 && nmin == 2)
			printf("5\n");
		else if ((max >= 4 && min == 3 && nmin == 2) || (max == 3 && nmax == 3))
			printf("6\n");
		else if (max >= 4 && min >= 4)
			printf("7\n");

		t--;

	}
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 long long
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long
#define pb                 push_back
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n'
#define PI                  3.14159265
#define N                  200005
ll n, m, k, a[N];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        cin >> m >> k;
        int ret = 0;
        if(n)
        {
        	ret++;
        	n--;
        }
        if(m)
        {
        	ret++;
        	m--;
        }
        if(k)
        {
        	ret++;
        	k--;
        }
        if(n and m)
        {
        	n--;
        	m--;
        	ret++;
        }
        if(m and k)
        {
        	m--;
        	k--;
        	ret++;
        }
        if(k and n)
        {
        	k--;
        	n--;
        	ret++;
        }
        if(m and n and k)
        {
        	ret++;
        }
        cout << ret << endl;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 long long
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long
#define pb                 push_back
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n'
#define PI                  3.14159265
#define N                  200005
ll n, m, k, a[N];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        cin >> m >> k;
        int ret = 0;
        if(n)
        {
        	ret++;
        	n--;
        }
        if(m)
        {
        	ret++;
        	m--;
        }
        if(k)
        {
        	ret++;
        	k--;
        }
        int ext = (n + m + k) / 2;
        a[0] = n;
        a[1] = m;
        a[2] = k;
        sort(a, a + 3);
        n = a[0];
        m = a[1];
        k = a[2];
        if(k and m)
        {
        	k--;
        	m--;
        	ret++;
        }
        if(k and n)
        {
        	k--;
        	n--;
        	ret++;
        }
        if(m and n)
        {
        	m--;
        	n--;
        	ret++;
        }
        if(m and n and k)ret++;
        cout << ret << endl;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#ifdef LOCAL
#define meminc             rlimit rlim;if (getrlimit(RLIMIT_STACK, &rlim)) return 1;rlim.rlim_cur = 1073741824;if (setrlimit(RLIMIT_STACK, &rlim)) return 2;
#else
#define meminc
#endif
#define ll                 long long
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long
#define pb                 push_back
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n'
#define PI                  3.14159265
#define N                  (int) 1e6 + 5
ll n, m, k, a[N];

int32_t main()
{
    meminc;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    cin >> tests;
    rep(test, 1, tests+1)
    {

        cin >> n;
        cin >> m >> k;
        int ret = 0;
        if(n)
        {
            ret++;
            n--;
        }
        if(m)
        {
            ret++;
            m--;
        }
        if(k)
        {
            ret++;
            k--;
        }
        int ext = (n + m + k) / 2;
        a[0] = n;
        a[1] = m;
        a[2] = k;
        sort(a, a + 3);
        n = a[0];
        m = a[1];
        k = a[2];
        if(k and m)
        {
            k--;
            m--;
            ret++;
        }
        if(k and n)
        {
            k--;
            n--;
            ret++;
        }
        if(m and n)
        {
            m--;
            n--;
            ret++;
        }
        if(m and n and k)ret++;
        cout << ret << endl;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#ifdef LOCAL
#define meminc             rlimit rlim;if (getrlimit(RLIMIT_STACK, &rlim)) return 1;rlim.rlim_cur = 1073741824;if (setrlimit(RLIMIT_STACK, &rlim)) return 2;
#else
#define meminc
#endif
#define ll                 long long
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long
#define pb                 push_back
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n'
#define PI                  3.14159265
#define N                  (int) 1e6 + 5
ll n, m, k, a[N];

int32_t main()
{
    meminc;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {

        cin >> n;
        cin >> m >> k;
        int ret = 0;
        if(n)
        {
            ret++;
            n--;
        }
        if(m)
        {
            ret++;
            m--;
        }
        if(k)
        {
            ret++;
            k--;
        }
        int ext = (n + m + k) / 2;
        a[0] = n;
        a[1] = m;
        a[2] = k;
        sort(a, a + 3);
        n = a[0];
        m = a[1];
        k = a[2];
        if(k and m)
        {
            k--;
            m--;
            ret++;
        }
        if(k and n)
        {
            k--;
            n--;
            ret++;
        }
        if(m and n)
        {
            m--;
            n--;
            ret++;
        }
        if(m and n and k)ret++;
        cout << ret << endl;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 long long
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long
#define pb                 push_back
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n'
#define PI                  3.14159265
#define N                  200005
ll n, m, k, a[N];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        cin >> m >> k;
        int ret = 0;
        if(n)
        {
        	ret++;
        	n--;
        }
        if(m)
        {
        	ret++;
        	m--;
        }
        if(k)
        {
        	ret++;
        	k--;
        }
        int ext = (n + m + k) / 2;
        a[0] = n;
        a[1] = m;
        a[2] = k;
        sort(a, a + 3);
        n = a[0];
        m = a[1];
        k = a[2];
        if(k and m)
        {
        	k--;
        	m--;
        	ret++;
        }
        if(k and n)
        {
        	k--;
        	n--;
        	ret++;
        }
        if(m and n)
        {
        	m--;
        	n--;
        	ret++;
        }
        if(m and n and k)ret++;.
        cout << ret << endl;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    int x=a+b+c;
    a=max({a, b, c}), c = min({a, b, c});
    b=x-a-c;
    if(c==0)cout<<min(2, a+b)<<"\n";
    else if(c==1)cout<<min(4, a+b)<<"\n";
    else if(c==2)cout<<min(5, a+b)<<"\n";
    else if(c==3)cout<<min(6, a+b)<<"\n";
    else cout<<min(7, a+b)<<"\n";
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    int x=a+b+c;
    a=max({a, b, c}), c = min({a, b, c});
    b=x-a-c;
    if(c==0){
        if(b==0){
            if(a==0)cout<<0<<"\n";
            else cout<<1<<"\n";
        }
        else cout<<2<<"\n";
    }
    else if(c==1){
        if(b==1)cout<<3<<"\n";
        else cout<<4<<"\n";
    }
    else if(c==2){
        if(b==2){
            if(a==2)cout<<4<<"\n";
            else cout<<5<<"\n";
        }
        else cout<<5<<"\n";
    }
    else if(c==3)cout<<6<<"\n";
    else cout<<7<<"\n";
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    int mn=min({a, b, c}), cnt = 0;
    if(mn>0){
        cnt=3;
        a--, b--, c--;
        mn=min({a, b, c});
        if(mn==0){
            int x = 0;
            if(a==mn)x++;
            if(b==mn)x++;
            if(c==mn)x++;
            if(x>=2)cout<<cnt<<"\n";
            else cout<<cnt+1<<"\n";
            return;
        }
        else if(mn==1)cout<<cnt+2<<"\n";
        else if(mn==2)cout<<cnt+3<<"\n";
        else cout<<cnt+4<<"\n";
    }
    else{
        int x = 0;
        if(a==mn)x++;
        if(b==mn)x++;
        if(c==mn)x++;
        if(x==3)cout<<0<<"\n";
        else if(x==2)cout<<1<<"\n";
        else if(x==1) cout<<min(4, a+b+c)<<"\n";
    }
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    int x=a+b+c;
    a=max({a, b, c}), c = min({a, b, c});
    b=x-a-c;
    if(c==0)cout<<min(4, a+b)<<"\n";
    else if(c==1)cout<<min(4, a+b)<<"\n";
    else if(c==2)cout<<min(5, a+b)<<"\n";
    else if(c==3)cout<<min(6, a+b)<<"\n";
    else cout<<min(7, a+b)<<"\n";
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
int a[3];
void foo(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a, a+3);
    int cnt = 0;
    if(a[0]>=1){
        cnt++;
        a[0]--;
    }
    if(a[1]>=1){
        cnt++;
        a[1]--;
    }
    if(a[2]>=1){
        cnt++;
        a[2]--;
    }
    if(a[2]>=1&&a[1]>=1){
        cnt++;
        a[2]--, a[1]--;
    }
    if(a[0]>=1&&a[2]>=1){
        cnt++;
        a[0]--, a[2]--;
    }
    if(a[0]>=1&&a[1]>=1){
        cnt++;
        a[0]--, a[1]--;
    }
    if(a[0]>=1&&a[1]>=1&&a[2]>=1)cnt++;
    cout<<cnt<<"\n";
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
int a[3];
void foo(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a, a+3);
    int cnt = 0;
    if(a[0]>=1){
        cnt++;
        a[0]--;
    }
    if(a[1]>=1){
        cnt++;
        a[1]--;
    }
    if(a[2]>=1){
        cnt++;
        a[2]--;
    }
    if(a[0]>=2&&a[1]>=1){
        cnt++;
        a[0]--, a[1]--;
    }
    if(a[1]>=2&&a[0]>=1){
        cnt++;
        a[1]--, a[0]--;
    }
    if(a[2]>=2&&a[1]>=1){
        cnt++;
        a[2]--, a[1]--;
    }
    if(a[2]>=2&&a[0]>=1){
        cnt++;
        a[2]--, a[0]--;
    }
    if(a[1]>=2&&a[2]>=1){
        cnt++;
        a[1]--, a[2]--;
    }
    if(a[0]>=2&&a[2]>=1){
        cnt++;
        a[0]--, a[2]--;
    }
    if(a[0]>=1&&a[1]>=1&&a[2]>=1)cnt++;
    cout<<cnt<<"\n";
}
int main(){
    speed;
    int t;
    cin>>t;
    while(t--)foo();
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t;
int main(int argc, char const *argv[])
{
    scanf("%d", &t);
    while (t--)
    {
        int a, b, c, ans = 0;
        scanf("%d%d%d", &a, &b, &c);
        if (a > b)
        {
            swap(a, b);
        }
        if (a > c)
        {
            swap(a, c);
        }
        if (b > c)
        {
            swap(b, c);
        }
        if (a)
        {
            a--;
            ans++;
        }
        if (b)
        {
            b--;
            ans++;
        }
        if (c)
        {
            c--;
            ans++;
        }
        if (a >= 3)
        {
            printf("7\n");
        }
        else
        {
            if (a == 2)
            {
                printf("6\n");
            }
            else
            {
                if (a == 1)
                {
                    printf("5\n");
                }
                else
                {
                    if (b && c)
                    {
                        printf("%d\n", ans + 1);
                    }
                    else
                    {
                        printf("%d\n", ans);
                    }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t;
int main(int argc, char const *argv[])
{
    scanf("%d", &t);
    while (t--)
    {
        int a, b, c, ans = 0;
        scanf("%d%d%d", &a, &b, &c);
        if (a)
        {
            a--;
            ans++;
        }
        if (b)
        {
            b--;
            ans++;
        }
        if (c)
        {
            c--;
            ans++;
        }
        if (a && b)
        {
            a--;
            b--;
            ans++;
        }
        if (b && c)
        {
            b--;
            c--;
            ans++;
        }
        if (a && c)
        {
            a--;
            c--;
            ans++;
        }
        if (a && b && c)
        {
            ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t;
int main(int argc, char const *argv[])
{
    scanf("%d", &t);
    while (t--)
    {
        int a, b, c, ans = 0;
        scanf("%d%d%d", &a, &b, &c);
        if (a > b)
        {
            swap(a, b);
        }
        if (a > c)
        {
            swap(a, c);
        }
        if (b > c)
        {
            swap(b, c);
        }
        if (a >= 4)
        {
            printf("7\n");
        }
        else
        {
            if (a == 3)
            {
                printf("6\n");
            }
            else
            {
                if (a == 2)
                {
                    if (c >= 3)
                    {
                        printf("5\n");
                    }
                    else
                    {
                        printf("4\n");
                    }
                }
                else
                {
                    if (a == 1)
                    {
                        if (b >= 2 && c >= 2)
                        {
                            printf("4\n");
                        }
                        else
                        {
                            printf("3\n");
                        }
                    }
                    else
                    {
                        if (b)
                        {
                            printf("2\n");
                        }
                        else
                        {
                            if (c)
                            {
                                printf("1\n");
                            }
                            else
                            {
                                printf("0\n");
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t;
int main(int argc, char const *argv[])
{
    scanf("%d", &t);
    while (t--)
    {
        int a, b, c, ans = 0;
        scanf("%d%d%d", &a, &b, &c);
        if (a > b)
        {
            swap(a, b);
        }
        if (a > c)
        {
            swap(a, c);
        }
        if (b > c)
        {
            swap(b, c);
        }
        if (a >= 4)
        {
            printf("7\n");
        }
        else
        {
            if (a == 3)
            {
                printf("6\n");
            }
            else
            {
                if (a == 2)
                {
                    if (c >= 3)
                    {
                        printf("5\n");
                    }
                    else
                    {
                        printf("4\n");
                    }
                }
                else
                {
                    if (a == 1)
                    {
                        if (b >= 2 && c >= 2)
                        {
                            printf("4\n");
                        }
                        else
                        {
                            printf("3\n");
                        }
                    }
                    else
                    {
                        if (b >= 2)
                        {
                            printf("3\n");
                        }
                        else
                        {
                            if (b)
                            {
                                printf("2\n");
                            }
                            else
                            {
                                if (c)
                                {
                                    printf("1\n");
                                }
                                else
                                {
                                    printf("0\n");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define inf 0x3f3f3f3f
#define INF 0xffffffff
#define il inline
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define fi first
#define se second
const int mod = 1e9+7;
il ll read()
{
	char ch = getchar();
	ll p = 1,data = 0;
	while(ch<'0'||ch>'9')
	{
		if(ch == '-')p = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		data = (data<<3)+(data<<1)+(ch^48);
		ch = getchar();
	}
	return p*data;
}
il ll lowbit(ll a)
{
	return a&(-a);
}
il ll qpow(ll a,ll b)
{
	ll r = 1;
	while(b)
	{
		if(b&1)r = a*r;
		a = a*a;
		b>>=1;
	}
	return r;
}
il ll gcd(ll a,ll b)
{
	while(b ^= a ^= b ^= a %= b);
	return a;
}
il ll lcm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
il ll inv(ll a,ll p)
{
	return qpow(a,p-2);
}
int main()
{
	int T = read();
	while(T--)
	{
		int a[4];
		int ans = 0;
		for(int i = 1; i <= 3; i++)
			a[i] = read();
		sort(a+1,a+4);
		if(a[1] >= 4 && a[2] >= 4 && a[3] >= 4)
			puts("7");
		else
		{
			if(a[1])
			{
				a[1]--,a[2]--,a[3]--;
				ans += 3;
			}
			if(a[1])
			{
				if(a[3])
					a[3]--,a[1]--,ans++;
				if(a[2] && a[1])
					a[2]--,a[1]--,ans++;
			}
			if(a[2] && a[3])
				a[2]--,a[3]--,ans++;
			if(a[1] && a[2] && a[3])
				ans++;
			printf("%d\n",ans);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int n,m;

vector<vector<int>> next(vector<vector<int>> v){
    vector<vector<int>> v1(n,vector<int>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int f=0;
            if(i     and v[i][j]==v[i-1][j])    f=1;
            if(j     and v[i][j]==v[i][j-1])    f=1;
            if(i<n-1 and v[i][j]==v[i+1][j])    f=1;
            if(j<m-1 and v[i][j]==v[i][j+1])    f=1;
            if(f)       v1[i][j]=!v[i][j];
            else        v1[i][j]= v[i][j];
        }
    }
    return v1;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt,ii=0,k=0;
    cin>>n>>m>>tt;
    vector<vector<int>> v(n,vector<int>(m)),v1(n,vector<int>(m));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            char x; cin>>x;
            v[i][j]=(x=='1');
        }

    map<int,vector<vector<int>>> mp;
    map<vector<vector<int>>,int> hs;

    v1=v;
    while(!hs[v1]){
        hs[v1]++;
        mp[k++]=v1;
        v1=next(v1);
    }

    while(ii++<tt)
    {
        int i,j,p;  cin>>i>>j>>p;
        cout<<mp[p%k][i-1][j-1]<<endl;
    }
    cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const short int N=1000;
short int n,m,ax[]={0,0,1,-1},ay[]={1,-1,0,0},man_dis[N][N];
bool vis[N][N],v[N][N],g[N][N];

void good(){
    for(short int i=0;i<n;i++){
        for(short int j=0;j<m;j++){
            bool f=0;
            if(i     and v[i][j]==v[i-1][j])    f=1;
            if(j     and v[i][j]==v[i][j-1])    f=1;
            if(i<n-1 and v[i][j]==v[i+1][j])    f=1;
            if(j<m-1 and v[i][j]==v[i][j+1])    f=1;
            g[i][j]=f;
        }
    }
}

void man_dist(){
    queue<pair<short int,short int>> q;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(g[i][j])
                man_dis[i][j]=0,q.push({i,j}),vis[i][j]=true;
    while(q.size()){
        short int y=q.front().first,x=q.front().second;
        q.pop();
        for(int i=0;i<4;i++){
            int nx=x+ax[i],ny=y+ay[i];
            if(nx<0||ny<0||nx>=m||ny>=n||vis[ny][nx])
                continue;
            man_dis[ny][nx]=man_dis[y][x]+1;
            vis[ny][nx]=true;
            q.push({ny,nx});
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt,ii=0;
    short int k=0;
    cin>>n>>m>>tt;
    for(short int i=0;i<n;i++)
        for(short int j=0;j<m;j++){
            char x; cin>>x;
            v[i][j]=(x=='1');
        }
    good();
    man_dist();

    while(ii++<tt)
    {
        short int i,j;
        long long p;  cin>>i>>j>>p;
        i--,j--;

        if(n+m==2){
            cout<<v[i][j]<<endl;
            continue;
        }
        short int f=man_dis[i][j];

        if(p<=f||!vis[i][j])
            cout<<v[i][j]<<endl;
        else
            cout<<(p-f+v[i][j])%2<<endl;
    }
    cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

short int n,m;
const short int N=1000;
vector<vector<bool>> v(N,vector<bool>(N)),g(N,vector<bool>(N));
vector<vector<short int>> mp(N,vector<short int>(N,-1));

void good(){
    for(short int i=0;i<n;i++){
        for(short int j=0;j<m;j++){
            bool f=0;
            if(i     and v[i][j]==v[i-1][j])    f=1;
            if(j     and v[i][j]==v[i][j-1])    f=1;
            if(i<n-1 and v[i][j]==v[i+1][j])    f=1;
            if(j<m-1 and v[i][j]==v[i][j+1])    f=1;
            g[i][j]=f;
        }
    }
}
short int man_dist(int i,int j){
    if(mp[i][j]!=-1)   return mp[i][j];

    queue<pair<pair<short int,short int>,short int>> q;
    map<pair<short int,short int>,bool> ma;
    q.push({{i,j},0});
    while(q.size()){
        short int r=q.front().first.first,c=q.front().first.second,d=q.front().second;
        q.pop();

        if(g[r][c])     return mp[i][j]=d;
        ma[{i,j}]=true;
        if(r     and !ma[{r-1,c}])    q.push({{r-1,c},d+1});
        if(c     and !ma[{r,c-1}])    q.push({{r,c-1},d+1});
        if(r<n-1 and !ma[{r+1,c}])    q.push({{r+1,c},d+1});
        if(c<m-1 and !ma[{r,c+1}])    q.push({{r,c+1},d+1});
    }
    return mp[i][j]=0;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt,ii=0;
    short int k=0;
    cin>>n>>m>>tt;
    for(short int i=0;i<n;i++)
        for(short int j=0;j<m;j++){
            char x; cin>>x;
            v[i][j]=x-'0';
        }
    good();
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(mp[i][j]==-1)
                man_dist(i,j);

    while(ii++<tt)
    {
        short int i,j;
        long long p;  cin>>i>>j>>p;
        i--,j--;

        if(n==m and n==1){
            cout<<v[i][j]<<endl;
            continue;
        }

        short int f=mp[i][j];
        if(p<=f)
            cout<<v[i][j]<<endl;
        else
            cout<<(p-f+v[i][j])%2<<endl;
    }
    cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int n,m;
const int N=1000;
vector<vector<bool>> v(N,vector<bool>(N)),g(N,vector<bool>(N));

void good(){
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int f=0;
            if(i     and v[i][j]==v[i-1][j])    f=1;
            if(j     and v[i][j]==v[i][j-1])    f=1;
            if(i<n-1 and v[i][j]==v[i+1][j])    f=1;
            if(j<m-1 and v[i][j]==v[i][j+1])    f=1;
            g[i][j]=f;
        }
    }
}
int man_dist(int i,int j){
    queue<pair<pair<int,int>,int>> q;
    map<pair<int,int>,bool> ma;
    q.push({{i,j},0});
    while(q.size()){
        int r=q.front().first.first,c=q.front().first.second;
        int d=q.front().second;
        q.pop();
        if(g[r][c]) return d;
        ma[{r,c}]=true;
        if(r     and !ma[{r-1,c}])    q.push({{r-1,c},d+1});
        if(c     and !ma[{r,c-1}])    q.push({{r,c-1},d+1});
        if(r<n-1 and !ma[{r+1,c}])    q.push({{r+1,c},d+1});
        if(c<m-1 and !ma[{r,c+1}])    q.push({{r,c+1},d+1});
    }
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt,ii=0,k=0;
    cin>>n>>m>>tt;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            char x; cin>>x;
            v[i][j]=(x=='1');
        }
    good();

    while(ii++<tt)
    {
        short int i,j;
        long long p;  cin>>i>>j>>p;
        i--,j--;

        int f=man_dist(i,j);
        if(p<=f)
            cout<<v[i][j]<<endl;
        else
            cout<<(p-f+v[i][j])%2<<endl;
    }
    cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int n,m;

vector<vector<bool>> next(vector<vector<bool>> v){
    vector<vector<bool>> v1(n,vector<bool>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int f=0;
            if(i     and v[i][j]==v[i-1][j])    f=1;
            if(j     and v[i][j]==v[i][j-1])    f=1;
            if(i<n-1 and v[i][j]==v[i+1][j])    f=1;
            if(j<m-1 and v[i][j]==v[i][j+1])    f=1;
            if(f)       v1[i][j]=!v[i][j];
            else        v1[i][j]= v[i][j];
        }
    }
    return v1;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt,ii=0,k=0;
    cin>>n>>m>>tt;
    vector<vector<bool>> v(n,vector<bool>(m)),v1(n,vector<bool>(m));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            char x; cin>>x;
            v[i][j]=(x=='1');
        }
    vector<vector<vector<bool>>> mp;
    map<vector<vector<bool>>,int> hs;

    v1=v;
    while(!hs[v1]){
        hs[v1]=++k;
        mp.push_back(v1);
        v1=next(v1);
    }
    int kk=hs[v1]-1;
    /*
    cout<<kk<<' '<<k<<endl;
    for(int l=0;l<k;l++){
        cout<<"k - "<<l<<endl;
        for(auto i:mp[l]){for(auto j:i)cout<<j;cout<<endl;}
    }
    */
    while(ii++<tt)
    {
        short int i,j;
        long long p;  cin>>i>>j>>p;
        if(p<k)
            cout<<mp[p][i-1][j-1]<<endl;
        else
            cout<<mp[kk+(p-k)%(k-kk)][i-1][j-1]<<endl;
    }
    cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}