1.

/**
 * ACM
 * UVa Status:  accepted
 * Run Time:    0.090
 * Category:    Simulation
 * @author Evgeni Pavlidis evgenipavlidis@yahoo.de
 */
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_M 251
#define MAX_N 251

#define VALID(x,y) ((x) > 0 && (x) <= m && (y) > 0 && (y) <= n)

static char image[MAX_N][MAX_M];
static int m,n;

void clearImage()
{
    for(int y=1; y <= n; y++)
        for(int x=1; x <= m; x++)
            image[y][x] = 'O';
}

void printImage()
{
    for(int y=1; y <= n; y++, cout << endl)
        for(int x=1; x <= m; x++)
            cout << image[y][x];
}

void fillRegion(int x, int y, char color, char oldColor)
{
    if(!VALID(x,y))
        return;

    if(image[y][x] != oldColor)
        return;

    image[y][x] = color;

   fillRegion(x,y+1, color, oldColor);
   fillRegion(x,y-1, color, oldColor);
   fillRegion(x+1,y, color, oldColor);
   fillRegion(x-1,y, color, oldColor);
}

int main()
{
    char command, color;
    string name;
    int x1,y1,x2,y2;
    n=1;
    m=1;

    while(true)
    {
        cin >> command;
        switch(command)
        {
            case 'I':
                cin >> m;
                cin >> n;
                clearImage();
            break;
            case 'C':
                clearImage();
            break;
            case 'L':
                cin >> x1;
                cin >> y1;
                cin >> color;
                image[y1][x1] = color;
            break;
            case 'V':
                cin >> x1;
                cin >> y1;
                cin >> y2;
                cin >> color;
                if(y1 > y2)
                    swap(y1,y2);
                for(int y=y1; y <= y2; y++)
                    image[y][x1] = color;
            break;
            case 'H':
                cin >> x1;
                cin >> x2;
                cin >> y1;
                cin >> color;
                if(x1 > x2)
                    swap(x1,x2);
                for(int x=x1; x <= x2; x++)
                    image[y1][x] = color;
            break;
            case 'K':
                cin >> x1;
                cin >> y1;
                cin >> x2;
                cin >> y2;
                cin >> color;
                if(y1 > y2)
                    swap(y1,y2);
                if(x1 > x2)
                    swap(x1,x2);
                for(int y=y1; y <= y2; y++)
                    for(int x=x1; x <= x2; x++)
                        image[y][x] = color;
            break;
            case 'F':
                cin >> x1;
                cin >> y1;
                cin >> color;
                if(image[y1][x1] != color)
                    fillRegion(x1,y1,color,image[y1][x1]);
            break;
            case 'S':
                cin >> name;
                cout << name << endl;
                printImage();
            break;
            case 'X':
                return 0;
            default:
                cin.ignore(1000000,'\n');
        }
    }
}