#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
int n, m;
int c[10];
int d[10];
int c1[10];
int d1[10];
int r[10][10];
int a[10][10];
int cnt;
int f[22][22];
int F[22][22];
int D[10];
int C[10];
bool g[10][10];
char s[10][10];
char S[10][10];
int best = -1;
int ID[26][26];
int now;
int u[22];
bool DEBUG;
int who[33];
int WHO[33];
int flow(int ver, int fl = 100) {
  if (ver == 21) return fl;
  if (u[ver] == now) return 0;
  u[ver] = now;
  if (f[ver][21]) {
    int t = flow(21, min(fl, f[ver][21]));
    return f[ver][21] -= t, f[21][ver] += t, t;
  }
  int from = 0, to = 20;
  if (ver >= 10 && ver <= 20) to = 10;
  if (ver < 10) from = 10;
  for (int i(from); i < (to); i++)
    if (f[ver][i]) {
      int t = flow(i, min(fl, f[ver][i]));
      if (t) return f[ver][i] -= t, f[i][ver] += t, t;
    }
  return 0;
}
void go(int x, int y, int id = 0) {
  if (y == m) {
    int sum = 0;
    for (int i(0); i < (10); i++) {
      int q = min(d[i], c[i]);
      sum += 2 * q;
      d1[i] = d[i] - q;
      c1[i] = c[i] - q;
    }
    for (int i(0); i < (10); i++)
      for (int j(0); j < (10); j++)
        if (g[i][j]) {
          int q = min(c1[i], d1[j]);
          c1[i] -= q, d1[j] -= q;
          sum += q;
          f[i][j + 10] = 1000;
          f[j + 10][i] = 0;
          f[j + 10][i] = q;
          f[i][20] = q;
          f[21][j + 10] = q;
        }
    for (int i(0); i < (10); i++) f[20][i] = c1[i];
    for (int i(0); i < (10); i++) f[i + 10][21] = d1[i];
    while (1) {
      now++;
      int t = flow(20);
      if (!t) break;
      sum += t;
    }
    if (best < sum) {
      best = sum;
      memcpy(r, a, sizeof a);
      memcpy(F, f, sizeof f);
      memcpy(D, d, sizeof d);
      memcpy(C, c, sizeof c);
      memcpy(WHO, who, sizeof who);
    }
    return;
  }
  if (x == n)
    go(0, y + 1, id);
  else {
    if (a[x][y])
      go(x + 1, y, id);
    else {
      if (x + 1 < n && !a[x + 1][y]) {
        int w = ID[s[x][y] - 'A'][s[x + 1][y] - 'A'];
        who[id + 1] = w;
        d[w]++;
        a[x][y] = a[x + 1][y] = id + 1;
        go(x + 2, y, id + 1);
        a[x + 1][y] = a[x][y] = 0;
        d[w]--;
      }
      if (y + 1 < m) {
        int w = ID[s[x][y] - 'A'][s[x][y + 1] - 'A'];
        who[id + 1] = w;
        d[w]++;
        a[x][y + 1] = a[x][y] = id + 1;
        go(x + 1, y, id + 1);
        a[x][y + 1] = a[x][y] = 0;
        d[w]--;
      }
    }
  }
}
string X[] = {"BY", "BW", "BR", "BB", "RY", "RW", "RR", "WY", "WW", "YY"};
bool used[111];
void change(int id, int newtype) {
  for (int i(0); i < (n); i++)
    for (int j(0); j < (m); j++)
      if (r[i][j] == id) {
        char &c1 = s[i][j];
        char &c2 = (r[i + 1][j] == id) ? s[i + 1][j] : s[i][j + 1];
        if (c1 == X[newtype][0]) {
          c2 = X[newtype][1];
        } else if (c1 == X[newtype][1]) {
          c2 = X[newtype][0];
        } else if (c2 == X[newtype][0]) {
          c1 = X[newtype][1];
        } else if (c2 == X[newtype][1]) {
          c1 = X[newtype][0];
        } else
          c1 = X[newtype][0], c2 = X[newtype][1];
        return;
      }
}
int main() {
  memset(ID, -1, sizeof(ID));
  for (int i(0); i < (10); i++)
    ID[X[i][0] - 'A'][X[i][1] - 'A'] = ID[X[i][1] - 'A'][X[i][0] - 'A'] = i;
  for (int i(0); i < (10); i++)
    for (int j(0); j < (10); j++)
      if (X[i][0] == X[j][0] || X[i][0] == X[j][1] || X[i][1] == X[j][0] ||
          X[i][1] == X[j][1])
        g[i][j] = 1;
  n = 7, m = 8;
  for (int i(0); i < (n); i++) cin >> s[i];
  for (int i(0); i < (10); i++) cin >> c[i];
  go(0, 0);
  cout << best << endl;
  for (int i(0); i < (10); i++) {
    int q = min(D[i], C[i]);
    d1[i] = D[i] - q;
    c1[i] = C[i] - q;
    C[i] -= q;
    best -= q * 2;
    for (int j(1); j < (n * m / 2 + 1); j++)
      if (WHO[j] == i && q) {
        used[j] = 1;
        q--;
      }
  }
  memset(f, 0, sizeof(f));
  for (int i(0); i < (10); i++)
    for (int j(0); j < (10); j++)
      if (g[i][j]) f[i][j + 10] = 1000;
  for (int i(0); i < (10); i++) f[20][i] = c1[i];
  for (int i(0); i < (10); i++) f[i + 10][21] = d1[i];
  while (1) {
    now++;
    int t = flow(20);
    if (!t) break;
    best -= t;
  }
  for (int i(0); i < (10); i++)
    for (int j(0); j < (10); j++)
      if (f[j + 10][i]) {
        int q = f[j + 10][i];
        for (int k(1); k < (n * m / 2 + 1); k++)
          if (WHO[k] == j && q && !used[k]) {
            C[i]--;
            q--;
            used[k] = true;
            change(k, i);
          }
      }
  for (int j(1); j < (n * m / 2 + 1); j++)
    if (!used[j]) {
      for (int i(0); i < (10); i++)
        if (C[i]) {
          C[i]--;
          change(j, i);
          break;
        }
    }
  for (int i(0); i < (n); i++) {
    for (int j(0); j < (m); j++) {
      cout << s[i][j];
      if (j != m - 1) {
        if (r[i][j] == r[i][j + 1])
          cout << '-';
        else
          cout << '.';
      }
    }
    puts("");
    for (int j(0); j < (m); j++) {
      if (i != n - 1) {
        if (r[i][j] == r[i + 1][j])
          cout << '|';
        else
          cout << '.';
        if (j != m - 1) cout << '.';
      }
    }
    if (i != n - 1) puts("");
  }
  return 0;
}
