import java.awt.*;
import java.math.*;
public class Mandelbrot[1] 
{
    private double x;
    private double y;    public double ComplexNumber()
    {
        x=0;
        y=0;
    }    public double ComplexNumber(double x0,double y0)
    {
       x=x0;
       y=y0;
    }    public double squaredmagnitude()
    {
       double squaredmagni=x*x+y*y;
       return squaredmagni;
    }    public double getx()
    {
       return x;
    }    public double gety()
    {
       return y;
    }    public void changewith(ComplexNumber C1)
    {
       double x1=C1.getx();
       double y1=C1.gety();
       double oldx=x;
       x=x*x-y*y+x1;
       y=2*oldx*y+y1;
    }    public String toString()
    {
      return x+"+"+y+"i";
    }    public static int iteration(ComplexNumber C1)
    {
       ComplexNumber C2=new ComplexNumber();
       int i=0;
       while (C2.squaredmagnitude()<4)
       {
          C2.changewith(C1);
          i++;
          if (i>=255)
          break;
       }
       return i;
    }}//=========================================================================================
//=========================================================================================
public class Mandelbrot
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader stdin= new BufferedReader(new InputStreamReader(System.in));                                                                                               
        String Type=stdin.readLine().trim();
        // get in the 6 numbers 
        int pixelofx=Integer.parseInt(stdin.readLine().trim());
        int pixelofy=Integer.parseInt(stdin.readLine().trim());                                                                                                            
            double startx=Double.parseDouble(stdin.readLine().trim());                                                                                                            
            double starty=Double.parseDouble(stdin.readLine().trim());                                                                                                            
            double endx=Double.parseDouble(stdin.readLine().trim());
            double endy=Double.parseDouble(stdin.readLine().trim());
            //change from image space to the complex number plane
            double unitx=(endx-startx)/(pixelofx-1);
            double unity=(endy-starty)/(pixelofy-1);     
        if (Type.equals("GREY"))
        {
            System.out.println("P2 "+pixelofx+" "+pixelofy+" 255");
            for (int iy=0; iy<pixelofy; iy++)
            {
                double nowy=starty+iy*unity;
                for (int ix=0; ix<pixelofx; ix++)
                {
                    ComplexNumber C=new ComplexNumber(startx+ix*unitx,nowy);                                                                                                      
                    int K=ComplexNumber.iteration(C);                                                                                                                             
                    System.out.print(K+" ");
                }
                System.out.println();                                                                                                                                             
            }                                                                                                                                                                     
         }
         else if (Type.equals("COLOR"))
         {
            System.out.println("P3 "+pixelofx+" "+pixelofy+" 255");
            for (int iy=0; iy<pixelofy; iy++)
            {
                double nowy=starty+iy*unity;
                for (int ix=0; ix<pixelofx; ix++)
                {
                    ComplexNumber C=new ComplexNumber(startx+ix*unitx,nowy);
                    int K=ComplexNumber.iteration(C);
                    float hue= (float)K/255;
                    float brightness = 1.0f - hue * hue;                                                                                                                          
                    Color color = Color.getHSBColor(hue, .8f, brightness);                                                                                                        
                    int blue=color.getBlue();
                    int green=color.getGreen();                                                                                                                                   
                    int red=color.getRed();                                                                                                                                   
                    System.out.print(red+" "+green+" "+blue+" "+"     \t");                                                                                                       
                }
                System.out.println("\t");
            }
         }                                                                                                                                                                     
             else System.out.println("not available command");                                                                                                                 
    }
}