Problem: Doctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors — blue, red, white or yellow.

The doctor wants to put 28 pills in a rectangular box 7 × 8 in size. Besides, each pill occupies exactly two neighboring cells and any cell contains exactly one half of a pill. Thus, the result is a four colored picture 7 × 8 in size.

The doctor thinks that a patient will recover sooner if the picture made by the pills will be special. Unfortunately, putting the pills in the box so as to get the required picture is not a very easy task. That's why doctor asks you to help. 

Doctor has some amount of pills of each of 10 painting types. They all contain the same medicine, that's why it doesn't matter which 28 of them will be stored inside the box.

Place the pills in the box so that the required picture was formed. If it is impossible to place the pills in the required manner, then place them so that the number of matching colors in all 56 cells in the final arrangement and the doctor's picture were maximum.

Input

First 7 lines contain the doctor's picture. Each line contains 8 characters, each character can be "B", "R", "W" and "Y" that stands for blue, red, white and yellow colors correspondingly.

Next four lines contain 10 numbers that stand for, correspondingly, the number of pills painted:

"BY" "BW" "BR" "BB"

"RY" "RW" "RR"

"WY" "WW"

"YY"

Those numbers lie within range from 0 to 28 inclusively. It is guaranteed that the total number of pills in no less than 28.

Output

Print on the first line the maximal number cells for which the colors match.

Then print 13 lines each containing 15 characters — the pills' position in the optimal arrangement. The intersections of odd lines and odd columns should contain characters "B", "R", "W" and "Y". All other positions should contain characters ".", "-" and "|". Use "-" and "|" to show which halves belong to one pill. See the samples for more clarification.

If there are several possible solutions, print any of them.

Examples

Input

WWWBBWWW
WWWBBWWW
YYWBBWWW
YYWBBWRR
YYWBBWRR
YYWBBWRR
YYWBBWRR
0 0 0 8
0 1 5
1 10
5


Output

53
W.W.W.B.B.W.W.W
|.|.|.|.|.|.|.|
W.W.W.B.B.W.W.W
...............
Y.Y.W.B.B.W.W-W
|.|.|.|.|.|....
Y.Y.W.B.B.W.R.R
............|.|
Y.Y.W.B.B.R.R.R
|.|.|.|.|.|....
Y.Y.W.B.B.W.R.R
............|.|
Y-Y.B-B.B-B.R.R


Input

WWWWWWWW
WBYWRBBY
BRYRBWYY
WWBRYWBB
BWWRWBYW
RBWRBWYY
WWWWWWWW
0 0 0 1
0 0 1
0 1
25


Output

15
W.Y.Y-Y.Y-Y.Y-Y
|.|............
W.Y.Y.Y.Y.B-B.Y
....|.|.|.....|
Y-Y.Y.Y.Y.Y-Y.Y
...............
Y.Y.Y.R.Y.Y.Y-Y
|.|.|.|.|.|....
Y.Y.Y.R.Y.Y.Y.Y
............|.|
Y-Y.Y.Y-Y.Y.Y.Y
....|.....|....
Y-Y.Y.Y-Y.Y.Y-Y

Solution (in CPP):

Solution:
#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;
}