#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n < 3 || m < 3) {
    cout << 0 << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << '.';
      }
      cout << "\n";
    }
    return 0;
  }
  if (n == 7 && m == 9)
    printf(
        "10\nAAA.BC...\n.ABBBCCCD\nEA.FBCDDD\nEEEF.GGGD\nEHFFFIGJ.\n.H.IIIGJ."
        "\nHHH..IJJJ");
  if (n == 8 && m == 7)
    printf(
        "9\nAAAB..C\n.A.BCCC\nDABBBEC\nDDDEEE.\nDFFF.EG\n.HFIGGG\n."
        "HFIIIG\nHHHI...");
  if (n == 3 && m == 3) printf("1\nAAA\n.A.\n.A.\n");
  if (n == 5 && m == 6) printf("4\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n..C..D");
  if (n == 9 && m == 7)
    printf(
        "10\nAAA.B..\n.ABBBC.\n.AD.BC.\nDDDECCC\nF.DEEEG\nFFFEGGG\nFHIIIJG\n.H."
        "I.J.\nHHHIJJJ");
  if (n == 8 && m == 8)
    printf(
        "10\nAAA.BCCC\n.ABBBDC.\nEA.FBDC.\nEEEFDDDG\nEHFFFGGG\n.HIII."
        "JG\nHHHIJJJ.\n...I..J.");
  if (n == 9 && m == 8)
    printf(
        "12\nAAA.BCCC\n.ABBBDC.\nEA.FBDC.\nEEEFDDDG\nEHFFFGGG\n."
        "HHHIIIG\nJHKKKIL.\nJJJK.IL.\nJ..K.LLL");
  if (n == 8 && m == 9)
    printf(
        "12\nAAABBB..C\n.AD.BECCC\n.AD.BEEEC\nFDDDGEHHH\nFFFIGGGH.\nFJ.IGK."
        "HL\n.JIIIKLLL\nJJJ.KKK.L");
  if (n == 9 && m == 9)
    printf(
        "13\nAAA.BCCC.\n.ABBB.CD.\n.AE.BFCD.\nEEEFFFDDD\nG.E.HFIII\nGGGJHHHI."
        "\nGK.JHL.IM\n.KJJJLMMM\nKKK.LLL.M");
  if (n == 3 && m == 4) printf("1\nAAA.\n.A..\n.A..");
  if (n == 5 && m == 3) printf("2\nAAA\n.A.\n.AB\nBBB\n..B");
  if (n == 4 && m == 4) printf("2\nAAA.\n.AB.\n.AB.\n.BBB");
  if (n == 3 && m == 6) printf("2\nAAA.B.\n.ABBB.\n.A..B.");
  if (n == 5 && m == 4) printf("2\nAAA.\n.AB.\n.AB.\n.BBB\n....");
  if (n == 5 && m == 5) printf("4\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nC.DDD");
  if (n == 4 && m == 3) printf("1\nAAA\n.A.\n.A.\n...");
  if (n == 3 && m == 5) printf("2\nAAA.B\n.ABBB\n.A..B");
  if (n == 6 && m == 3) printf("2\nAAA\n.A.\n.AB\nBBB\n..B\n...");
  if (n == 4 && m == 5) printf("2\nAAA.B\n.ABBB\n.A..B\n.....");
  if (n == 3 && m == 7) printf("3\nAAABCCC\n.A.B.C.\n.ABBBC.");
  if (n == 7 && m == 3) printf("3\nAAA\n.A.\n.AB\nBBB\n.CB\n.C.\nCCC");
  if (n == 3 && m == 8) printf("3\nAAA.BCCC\n.ABBB.C.\n.A..B.C.");
  if (n == 8 && m == 3) printf("3\nAAA\n.A.\n.AB\nBBB\n.CB\n.C.\nCCC\n...");
  if (n == 4 && m == 6) printf("3\nAAABBB\n.AC.B.\n.AC.B.\n.CCC..");
  if (n == 6 && m == 4) printf("3\nAAA.\n.AB.\n.AB.\nCBBB\nCCC.\nC...");
  if (n == 3 && m == 9) printf("4\nAAABCCC.D\n.A.B.CDDD\n.ABBBC..D");
  if (n == 9 && m == 3)
    printf("4\nAAA\n.A.\n.AB\nBBB\nC.B\nCCC\nC.D\nDDD\n..D");
  if (n == 4 && m == 7) printf("4\nAAABBB.\n.AC.BD.\n.AC.BD.\n.CCCDDD");
  if (n == 7 && m == 4) printf("4\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\n...D");
  if (n == 6 && m == 5) printf("4\nAAA.B\n.ABBB\n.AC.B\nCCCD.\n..CD.\n..DDD");
  if (n == 4 && m == 8) printf("4\nAAA.BCCC\n.ABBBDC.\n.A..BDC.\n....DDD.");
  if (n == 8 && m == 4)
    printf("4\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\n...D\n....");
  if (n == 5 && m == 7)
    printf("5\nAAA.B..\n.ABBBC.\nDA.EBC.\nDDDECCC\nD.EEE..");
  if (n == 7 && m == 5)
    printf("5\nAAA.B\n.ABBB\n.AC.B\nCCCD.\n.ECD.\n.EDDD\nEEE..");
  if (n == 4 && m == 9) printf("5\nA..CCCE..\nAAABCDEEE\nABBBCDE..\n...BDDD..");
  if (n == 6 && m == 6)
    printf("5\nAAA.B.\n.ABBB.\n.A.CB.\nDCCCE.\nDDDCE.\nD..EEE");
  if (n == 9 && m == 4)
    printf("5\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\nEEED\n.E..\n.E..");
  if (n == 5 && m == 8)
    printf("6\nAAA.BCCC\n.ABBBDC.\nEA.FBDC.\nEEEFDDD.\nE.FFF...");
  if (n == 8 && m == 5)
    printf("6\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nCEDDD\n.EFFF\nEEEF.\n...F.");
  if (n == 6 && m == 7)
    printf("6\nA..C..E\nAAACEEE\nABCCCFE\n.B.D.F.\nBBBDFFF\n..DDD..");
  if (n == 7 && m == 6)
    printf("6\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n.EC.FD\n.EFFF.\nEEE.F.");
  if (n == 5 && m == 9)
    printf("7\nAAA.BCCC.\n.ABBBDC..\nEA.FBDCG.\nEEEFDDDG.\nE.FFF.GGG");
  if (n == 9 && m == 5)
    printf("7\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nCEDDD\n.EEEF\nGEFFF\nGGG.F\nG....");
  if (n == 6 && m == 8)
    printf("7\nAAA.BCCC\n.ABBBDC.\n.AE.BDC.\nEEEFDDDG\n..EF.GGG\n..FFF..G");
  if (n == 8 && m == 6)
    printf("7\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n..CE.D\nFEEEG.\nFFFEG.\nF..GGG");
  if (n == 7 && m == 7)
    printf("8\nAAABCCC\n.A.B.C.\nDABBBCE\nDDDFEEE\nDG.F.HE\n.GFFFH.\nGGG.HHH");
  if (n == 6 && m == 9)
    printf(
        "8\nAAA.B..C.\n.ABBBCCC.\n.A.DBE.C.\nFDDDGEEEH\nFFFDGEHHH\nF..GGG..H");
  if (n == 9 && m == 6)
    printf(
        "8\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\nE.CF.D\nEEEF..\nEGFFFH\n.G."
        "HHH\nGGG..H");
  if (n == 7 && m == 8)
    printf(
        "9\nA.BBB..C\nAAABDCCC\nA.EBDDDC\nEEEFDGGG\n.HEF.IG.\n.HFFFIG.\nHHH."
        "III.");
  return 0;
}
