#include <bits/stdc++.h>
using namespace std;
struct kraw {
  int a, cap;
};
vector<vector<int> > podzial(7, vector<int>(8, -1));
vector<int> ilNaObr(10, 0), ilMam(10, 0);
int nr = -1, mam = 0;
string tab[] = {"BB", "BR", "BW", "BY", "RR", "RW", "RY", "WW", "WY", "YY"};
vector<string> P(7);
vector<vector<kraw> > G(22);
const int INF = 100;
int odp = 57;
vector<vector<int> > odpPodzial;
vector<string> odpP1, odpP2;
vector<string> odpP(13);
const int base = 1000000007;
set<int> H;
int Szukaj(string a) {
  if (a[0] > a[1]) swap(a[0], a[1]);
  for (int i = 0; i < 10; ++i)
    if (tab[i] == a) return i;
}
int R(string a, string b) {
  return min((a[0] != b[0]) + (a[1] != b[1]), (a[0] != b[1]) + (a[1] != b[0]));
}
void Licz() {
  for (int i = 1; i <= 10; ++i) {
    G[0][i - 1].cap = ilNaObr[i - 1];
    G[i][10].cap = 0;
  }
  for (int i = 11; i <= 20; ++i) {
    G[i][0].cap = ilMam[i - 11];
    G[21][i - 11].cap = 0;
  }
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) {
      G[i][j - 11].cap = INF;
      G[j][i].cap = 0;
    }
  }
  vector<string> p1, p2;
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) {
      if (R(tab[i - 1], tab[j - 11]) == 0) {
        int m = min(ilNaObr[i - 1], ilMam[i - 1]);
        G[0][i - 1].cap -= m;
        G[j][0].cap -= m;
        for (int k = 0; k < m; ++k) {
          p1.push_back(tab[i - 1]);
          p2.push_back(tab[i - 1]);
        }
      }
      if (R(tab[i - 1], tab[j - 11]) == 2) {
        G[i][j - 11].cap = 0;
        G[j][i].cap = 0;
      }
    }
  }
  int flow = 0;
  while (true) {
    vector<int> pop(22, -1);
    queue<int> Q;
    Q.push(0);
    pop[0] = 0;
    while (!Q.empty()) {
      int akt = Q.front();
      Q.pop();
      for (int i = 0; i < G[akt].size(); ++i) {
        if (pop[G[akt][i].a] == -1 && G[akt][i].cap != 0) {
          pop[G[akt][i].a] = akt;
          Q.push(G[akt][i].a);
        }
      }
    }
    if (pop[21] == -1) break;
    vector<int> path;
    int akt = 21;
    while (akt != 0) {
      path.push_back(akt);
      akt = pop[akt];
    }
    path.push_back(0);
    reverse(path.begin(), path.end());
    int c = INF;
    for (int i = 0; i < (int)path.size() - 1; ++i)
      for (int j = 0; j < G[path[i]].size(); ++j)
        if (G[path[i]][j].a == path[i + 1]) c = min(c, G[path[i]][j].cap);
    for (int i = 0; i < (int)path.size() - 1; ++i) {
      for (int j = 0; j < G[path[i]].size(); ++j)
        if (G[path[i]][j].a == path[i + 1]) G[path[i]][j].cap -= c;
      for (int j = 0; j < G[path[i + 1]].size(); ++j)
        if (G[path[i + 1]][j].a == path[i]) G[path[i + 1]][j].cap += c;
    }
    flow += c;
  }
  for (int i = 11; i <= 20; ++i) {
    for (int j = 1; j <= 10; ++j) {
      int il = G[i][j].cap;
      for (int k = 0; k < il; ++k) {
        p1.push_back(tab[j - 1]);
        p2.push_back(tab[i - 11]);
      }
    }
  }
  int nowy = 2 * (28 - (int)p1.size()) + flow;
  if (nowy < odp) {
    odp = nowy;
    odpPodzial = podzial;
    odpP1 = p1;
    odpP2 = p2;
  }
}
void StworzG() {
  for (int i = 1; i <= 10; ++i) G[0].push_back({i, 0});
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) G[i].push_back({j, 0});
    G[i].push_back({0, 0});
  }
  for (int i = 11; i <= 20; ++i) {
    G[i].push_back({21, 0});
    for (int j = 1; j <= 10; ++j) G[i].push_back({j, 0});
  }
  for (int i = 11; i <= 20; ++i) G[21].push_back({i, 0});
}
void rec(int x, int y, int kier) {
  ++nr;
  podzial[x][y] = nr;
  if (kier == 0)
    podzial[x][y + 1] = nr;
  else
    podzial[x + 1][y] = nr;
  string para = "";
  para += P[x][y];
  if (kier == 0)
    para += P[x][y + 1];
  else
    para += P[x + 1][y];
  ++ilNaObr[Szukaj(para)];
  ++mam;
  if (mam == 28) {
    int h = 0;
    for (int i = 0; i < 10; ++i) h = h * base + ilNaObr[i];
    if (H.find(h) == H.end()) {
      Licz();
      H.insert(h);
    }
  }
  int nx = -1, ny = -1;
  for (int i = x; i < 7; ++i) {
    for (int j = 0; j < 8; ++j) {
      if (podzial[i][j] == -1) {
        nx = i;
        ny = j;
        break;
      }
    }
    if (nx != -1) break;
  }
  if (nx != -1) {
    if (ny + 1 < 8 && podzial[nx][ny + 1] == -1) rec(nx, ny, 0);
    if (nx + 1 < 7 && podzial[nx + 1][ny] == -1) rec(nx, ny, 1);
  }
  podzial[x][y] = -1;
  if (kier == 0)
    podzial[x][y + 1] = -1;
  else
    podzial[x + 1][y] = -1;
  --ilNaObr[Szukaj(para)];
  --nr;
  --mam;
}
void Wypisz() {
  multiset<string> wsz;
  for (int i = 0; i < 10; ++i)
    for (int j = 0; j < ilMam[i]; ++j) wsz.insert(tab[i]);
  cout << 56 - odp << endl;
  vector<bool> jest(odpP1.size(), true);
  for (int i = 0; i < 28; ++i) {
    int a = -1, b, c, d;
    for (int j = 0; j < 7; ++j) {
      for (int k = 0; k < 8; ++k) {
        if (odpPodzial[j][k] == i) {
          if (a == -1) {
            a = j;
            b = k;
          } else {
            c = j;
            d = k;
          }
        }
      }
    }
    string x = "";
    x += P[a][b];
    x += P[c][d];
    if (x[0] > x[1]) swap(x[0], x[1]);
    int nr = -1;
    for (int j = 0; j < odpP1.size(); ++j) {
      if (odpP1[j] == x && jest[j]) {
        nr = j;
        break;
      }
    }
    if (nr != -1) {
      if (R(x, odpP2[nr]) == 1) {
        if (P[a][b] == odpP2[nr][0]) P[c][d] = odpP2[nr][1];
        if (P[a][b] == odpP2[nr][1]) P[c][d] = odpP2[nr][0];
        if (P[c][d] == odpP2[nr][0]) P[a][b] = odpP2[nr][1];
        if (P[c][d] == odpP2[nr][1]) P[a][b] = odpP2[nr][0];
      }
      wsz.erase(wsz.find(odpP2[nr]));
      jest[nr] = false;
    } else {
      P[a][b] = 'Q';
      P[c][d] = 'Q';
    }
  }
  string t(15, '.');
  for (int i = 0; i < 13; ++i) odpP[i] = t;
  for (int i = 0; i < 7; ++i)
    for (int j = 0; j < 8; ++j) odpP[2 * i][2 * j] = P[i][j];
  for (int i = 0; i < 28; ++i) {
    int a = -1, b, c, d;
    for (int j = 0; j < 7; ++j) {
      for (int k = 0; k < 8; ++k) {
        if (odpPodzial[j][k] == i) {
          if (a == -1) {
            a = j;
            b = k;
          } else {
            c = j;
            d = k;
          }
        }
      }
    }
    if (odpP[2 * a][2 * b] == 'Q') {
      string x = *(wsz.begin());
      odpP[2 * a][2 * b] = x[0];
      odpP[2 * c][2 * d] = x[1];
      wsz.erase(wsz.find(x));
    }
    if (a == c)
      odpP[2 * a][2 * b + 1] = '-';
    else
      odpP[2 * a + 1][2 * b] = '|';
  }
  for (int i = 0; i < 13; ++i) cout << odpP[i] << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 7; ++i) cin >> P[i];
  cin >> ilMam[3] >> ilMam[2] >> ilMam[1] >> ilMam[0];
  cin >> ilMam[6] >> ilMam[5] >> ilMam[4];
  cin >> ilMam[8] >> ilMam[7];
  cin >> ilMam[9];
  StworzG();
  rec(0, 0, 0);
  rec(0, 0, 1);
  Wypisz();
  return 0;
}
