#include <iostream.h>
#include <assert.h>
#include <vector.h>
#include <algo.h>

class Rectangle {
public:
  Rectangle(bool p, int xb, int yb, int xe, int ye) {
    positive = p;
    xbegin = xb;
    ybegin = yb;
    xend = xe;
    yend = ye;
  }
  Rectangle(istream& inn) {
    char key;
    inn >> key;
    positive = (key == 'a');
    inn >> xbegin >> ybegin >> xend >> yend;
    assert(xbegin <= xend);
    assert(ybegin <= yend);
  }
  bool inrect(const int x, const int y) {
    if (x < xbegin) return false;
    if (y < ybegin) return false;
    if (x > xend) return false;
    if (y > yend) return false;
    return(true);
  }
  int maxx() {
    return(xend);
  }
  int maxy() {
    return(yend);
  }
  bool positive;
private:
  int xbegin,xend,ybegin,yend;
};

class Square {
public:
  Square(const int xx, const int yy, const int sz) 
    : xb(xx), yb(yy), size(sz) {}
  int xb, yb, size;
  bool insquare(const int x, const int y) {
    if (x < xb) return false;
    if (y < yb) return false;
    if (x > xb+size) return false;
    if (y > yb+size) return false;
  }
  Rectangle* toRect() {
    Rectangle* r = new Rectangle(false,xb,yb,xb+size,yb+size);
    return(r);
  }
};

class Shape {
public:
  Shape(istream& inn);
  ~Shape();
  bool inShape(const int x, const int y);
  int whichSquare(const int x, const int y);
  void printShape(ostream& outt);
  pair<int,int>* smallestInCut();
  void solve();
private:
  vector<Rectangle*> rectvect;
  vector<Square*> sqvect;
  Square* maxSquare(const pair<int,int> coord);
//  Square* maxSquare(const int x, const int y);
  int maxx;
  int maxy;
  int bestsol;
  int cycle;
};

Shape::Shape(istream & inn) {
  maxx = 0;
  maxy = 0;
  while (!inn.eof()) {
    Rectangle* r = new Rectangle(inn);
    rectvect.push_back(r);
    int rmaxx = r->maxx();
    int rmaxy = r->maxy();
    if (rmaxx > maxx) maxx = rmaxx;
    if (rmaxy > maxy) maxy = rmaxy;
  }
  bestsol = 68; // artificial for connecticut.
//  bestsol = maxx*maxy;
  cycle = 0;
}

Shape::~Shape() {
}

bool Shape::inShape(const int x, const int y) {
  vector<Rectangle*>::iterator first = rectvect.begin();
  vector<Rectangle*>::iterator last = rectvect.end();
  bool inShape = false;
  while (first != last) {
    Rectangle* r = * (first++);
    if (r->inrect(x,y)) {
      inShape = (r->positive);
    }
  }
  return(inShape);
}

int Shape::whichSquare(const int x, const int y) {
  if (!inShape(x,y)) return(-2);
  vector<Square*>::iterator first = sqvect.begin();
  vector<Square*>::iterator last = sqvect.end();
  int index=0;
  while (first != last) {
    Square* r = *(first++);
    if (r->insquare(x,y))
      return(index);
    index++;
  }
  return(-1);  // in the Cut
}

void Shape::printShape(ostream& outt) {
  outt << endl;
  for (int y=0;y<=maxy;y++) {
    for (int x=0;x<=maxx;x++) {
      int index = whichSquare(x,y);
      if (index == -2) outt << ' ';
      else if (index == -1) outt << '#';
      else outt << (char)('A'+index);
    }
    outt << endl;
  }
}

Square* Shape::maxSquare(const pair<int,int> coord) {
  int x = coord.first;
  int y = coord.second;
  assert (whichSquare(x,y) == -1);
  int size = 0;
  while (whichSquare(x+size,y) == -1) size++; 
  for (int yi=1;yi<size;yi++) {
    for (int xi=0;xi<size;xi++) {
      if (whichSquare(x+xi,y+yi) != -1) 
        size = min(size,max(yi,xi));
    }
  }
  return(new Square(x,y,size-1));
}

pair<int,int>* Shape::smallestInCut() {
  for (int y=0;y<=maxy;y++) 
    for (int x=0;x<=maxx;x++) 
      if (whichSquare(x,y) == -1)
        return(new pair<int,int>(x,y));
  return(NULL);
}

void Shape::solve() {
  if (sqvect.size() > bestsol) return;
  pair<int,int>* coord = smallestInCut();
  if (coord == NULL) {
    bestsol = sqvect.size();
    printShape(cout);
    cout << sqvect.size() << " squares\n";
  } else {
    Square* sq = maxSquare(*coord);
    sqvect.push_back(sq);
//    cout << "pushing\n";
    while (sq->size >= 0) {
        if (++cycle > 1000000) {
          printShape(cout);
          cout << "Partial Progress\n";
          cycle = 0;
        }
//      cout << "using\n";
//      printShape(cout);
      solve();
      (sq->size)--;
    }
//    cout << "popping\n";
    sqvect.pop_back();
    delete(sq);
  }
}

int main() {
  // get input data
  Shape* s = new Shape(cin);
  s->solve();
  delete s;
}
