https://www.codechef.com/problems/NTCOL

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here

	try {
	    
	    Scanner scn = new Scanner(System.in);
	    
	    int t = scn.nextInt();
	    
	    while(t--!=0){
	        
	        
	        int n = scn.nextInt();
	        
	        int m = scn.nextInt();
	        
	        int[] freq = new int[3];
	        
	        char[] colors = new char[3];
	        
	        freq[0] = scn.nextInt();
	        colors[0] = 'R';
	        
	        freq[1] = scn.nextInt();
	        colors[1] = 'G';
	        
	        freq[2] = scn.nextInt();
	        colors[2] = 'B';
	        
	        
	        for(int i=0;i<2;i++){
	            
	            for(int j=i;j<2;j++){
	                
	                if(freq[j]>freq[j+1]){
	                    
	                    int temp = freq[j];
	                    
	                    char c = colors[j];
	                    
	                    freq[j] = freq[j+1];
	                    
	                    colors[j] = colors[j+1];
	                    
	                    freq[j+1] = temp;
	                    
	                    colors[j+1] = c;
	                    
	                    
	                }
	                
	                
	            }
	            
	            
	        }
	       
	        
	      
	      boolean level = true;
	      
	      for(int i=0;i<n;i++){
	          
	          
	          
	          boolean cell = level;
	          
	          for(int j=0;j<m;j++){
	              
	              if(cell && freq[1]!=0){
	                  System.out.print(colors[1]);
	                  freq[1]--;
	              }
	              else if(!cell && freq[0]!=0){
	                System.out.print(colors[0]);
	                freq[0]--;

	              }
	              else{
	                System.out.print(colors[2]);

	              }
	              
	              cell = !cell;
	              
	          }
	          
	          level = !level;
	          System.out.println();
	       
	          
	          
	      }
	      
	      
	        
	        
	    }
	    
	    
	    
	} catch(Exception e) {
	} finally {
	}
	
	
	
}

}

Code giving TLE , please help