Language: C++

function bomb(y,x,color){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || xx<0 || yy>=12 || xx>=6)continue;
      if(yx[yy][xx]==color) {
         CNT++;
         if(CNT==4)p.push([yy,xx]);
         yx[yy][xx]=color+CNT;
         bomb(yy,xx,color);
      }
   }
}
function BOMB(y,x,color){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || xx<0 || yy>=12 || xx>=6)continue;
      if(yx[yy][xx]==color){
         yx[yy][xx]=".";
         BOMB(yy,xx,color);
      }else if(yx[yy][xx]=="O"){
         yx[yy][xx]=".";
      }
   }
}
function up(y,x){
   var yy=y;
   while(y>0){
      y--;
      if(yx[y][x]!="."){
         yx[yy][x]=yx[y][x];
         yx[y][x]=".";
         break;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var I=0;I<n;I++){
   var yx=[];
   for(var i=0;i<12;i++){
      var arr=(Arr.shift()).split("");
      yx.push(arr);
   }
   var result=0;  
   while(true){
        var p=[];
        var CNT;
         for(var i=0;i<12;i++){
               for(var j=0;j<6;j++){
                  if(yx[i][j]=="R"){CNT=1;yx[i][j]="R"+CNT;bomb(i,j,"R");}
                  if(yx[i][j]=="G"){CNT=1;yx[i][j]="G"+CNT;bomb(i,j,"G");}
                  if(yx[i][j]=="B"){CNT=1;yx[i][j]="B"+CNT;bomb(i,j,"B");}
                  if(yx[i][j]=="Y"){CNT=1;yx[i][j]="Y"+CNT;bomb(i,j,"Y");}
                  if(yx[i][j]=="P"){CNT=1;yx[i][j]="P"+CNT;bomb(i,j,"P");}
               }
         }
         for(var i=0;i<12;i++){
            for(var j=0;j<6;j++){
               yx[i][j]=yx[i][j].slice(0,1);
            }
         }
         if(p.length==0)break;
         result++; 
         p.forEach(function(v){
            var i=v[0];
            var j=v[1];
            var color=yx[i][j];
            if(color!=".")BOMB(i,j,color);
         });
         for(var i=11;i>0;i--){
            for(var j=0;j<6;j++){
               if(yx[i][j]==".")up(i,j);
            }
         }
   }
   console.log(result);

Compiler output:
a.cc:42:21: warning: multi-character character constant [-Wmultichar]
   42 | var input = require('fs').readFileSync('/dev/stdin', 'utf8');
      |                     ^~~~
a.cc:42:40: warning: multi-character literal with 10 characters exceeds 'int' size of 4 bytes
   42 | var input = require('fs').readFileSync('/dev/stdin', 'utf8');
      |                                        ^~~~~~~~~~~~
a.cc:42:54: warning: multi-character character constant [-Wmultichar]
   42 | var input = require('fs').readFileSync('/dev/stdin', 'utf8');
      |                                                      ^~~~~~
a.cc:1:1: error: 'function' does not name a type; did you mean 'union'?
    1 | function bomb(y,x,color){
      | ^~~~~~~~
      | union
a.cc:16:1: error: 'function' does not name a type; did you mean 'union'?
   16 | function BOMB(y,x,color){
      | ^~~~~~~~
      | union
a.cc:31:1: error: 'function' does not name a type; did you mean 'union'?
   31 | function up(y,x){
      | ^~~~~~~~
      | union
a.cc:42:1: error: 'var' does not name a type
   42 | var input = require('fs').readFileSync('/dev/stdin', 'utf8');
      | ^~~
a.cc:43:1: error: 'var' does not name a type
   43 | var Arr=(input.trim()).split("\n");
      | ^~~
a.cc:44:1: error: 'var' does not name a type
   44 | var n=Arr.shift()-0;
      | ^~~
a.cc:45:1: error: expected unqualified-id before 'for'
   45 | for(var I=0;I<n;I++){
      | ^~~
a.cc:45:13: error: 'I' does not name a type
   45 | for(var I=0;I<n;I++){
      |             ^
a.cc:45:17: error: 'I' does not name a type
   45 | for(var I=0;I<n;I++){
      |                 ^