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>
using namespace std;
const int le = 20, ri = 21;
char z[] = "BRWY";
int a[7][8], P[4][4], L[10], R[10], A[10], B[10], T = -1, p[22][22];
bool v[7][8], w[10][10], r2[7][8], d2[7][8], u[22];
char s[13][15], S[13][15];
void add(int x, int y) {
  static int t = 0;
  P[x][y] = P[y][x] = t, L[t] = x, R[t] = y, t++;
}
bool f2(int x) {
  if (x == ri) return 1;
  u[x] = 1;
  for (int i = 21; i; i--)
    if (p[x][i] && !u[i] && f2(i)) {
      p[x][i]--, p[i][x]++;
      return 1;
    }
  return 0;
}
void gg() {
  int c[10], D[10][10], t = 0;
  memcpy(c, A, sizeof c), memset(D, 0, sizeof D);
  for (int i = 0; i < 10; i++) D[i][i] = min(A[i], B[i]), t += D[i][i] * 2;
  if (28 + t / 2 <= T) return;
  memset(p, 0, sizeof p);
  for (int i = 0; i < 10; i++)
    if (A[i] > B[i])
      p[le][i] = A[i] - B[i];
    else if (A[i] < B[i])
      p[i + 10][ri] = B[i] - A[i];
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (w[i][j]) {
        int u = min(p[le][i], p[j + 10][ri]);
        p[le][i] -= u, p[j + 10][ri] -= u, p[i][j + 10] = 28, t += u,
                                                    D[i][j] += u;
      }
  for (; memset(u, 0, sizeof u), f2(le); t++)
    ;
  if (t <= T) return;
  T = t;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++) D[i][j] += p[j + 10][i];
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++) s[i * 2][j * 2] = '.';
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (r2[i][j]) {
        int o = P[a[i][j]][a[i][j + 1]];
        for (int k = 0; k < 10; k++)
          if (D[k][o]) {
            D[k][o]--, c[k]--;
            if (a[i][j] == R[k] || a[i][j + 1] == L[k]) swap(L[k], R[k]);
            s[i * 2][j * 2] = z[L[k]], s[i * 2][j * 2 + 2] = z[R[k]];
            break;
          }
      }
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (d2[i][j]) {
        int o = P[a[i][j]][a[i + 1][j]];
        for (int k = 0; k < 10; k++)
          if (D[k][o]) {
            D[k][o]--, c[k]--;
            if (a[i][j] == R[k] || a[i + 1][j] == L[k]) swap(L[k], R[k]);
            s[i * 2][j * 2] = z[L[k]], s[i * 2 + 2][j * 2] = z[R[k]];
            break;
          }
      }
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (s[i * 2][j * 2] == '.' && r2[i][j])
        for (int k = 0; k < 10; k++)
          if (c[k]) {
            c[k]--, s[i * 2][j * 2] = z[L[k]], s[i * 2][j * 2 + 2] = z[R[k]];
            break;
          }
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (s[i * 2][j * 2] == '.' && d2[i][j])
        for (int k = 0; k < 10; k++)
          if (c[k]) {
            c[k]--, s[i * 2][j * 2] = z[L[k]], s[i * 2 + 2][j * 2] = z[R[k]];
            break;
          }
  memcpy(S, s, sizeof s);
}
void ff(int x, int y) {
  if (x == 7) {
    gg();
    return;
  }
  if (y == 8) {
    ff(x + 1, 0);
    return;
  }
  if (v[x][y]) {
    ff(x, y + 1);
    return;
  }
  if (y < 7 && !v[x][y + 1])
    v[x][y] = v[x][y + 1] = 1, B[P[a[x][y]][a[x][y + 1]]]++,
    s[x * 2][y * 2 + 1] = '-', r2[x][y] = 1, ff(x, y + 1),
    v[x][y] = v[x][y + 1] = 0, B[P[a[x][y]][a[x][y + 1]]]--,
    s[x * 2][y * 2 + 1] = '.', r2[x][y] = 0;
  if (x < 6 && !v[x + 1][y])
    v[x][y] = v[x + 1][y] = 1, B[P[a[x][y]][a[x + 1][y]]]++,
    s[x * 2 + 1][y * 2] = '|', d2[x][y] = 1, ff(x, y + 1),
    v[x][y] = v[x + 1][y] = 0, B[P[a[x][y]][a[x + 1][y]]]--,
    s[x * 2 + 1][y * 2] = '.', d2[x][y] = 0;
}
int main() {
  for (int i = 0; i < 7; i++) {
    char s[100];
    scanf("%s", s);
    for (int j = 0; j < 8; j++)
      if (s[j] == 'B')
        a[i][j] = 0;
      else if (s[j] == 'R')
        a[i][j] = 1;
      else if (s[j] == 'W')
        a[i][j] = 2;
      else if (s[j] == 'Y')
        a[i][j] = 3;
  }
  add(0, 3), add(0, 2), add(0, 1), add(0, 0), add(1, 3), add(1, 2), add(1, 1),
      add(2, 3), add(2, 2), add(3, 3);
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (L[i] == L[j] || L[i] == R[j] || R[i] == L[j] || R[i] == R[j])
        w[i][j] = 1;
  for (int i = 0; i < 10; i++) scanf("%d", A + i);
  memset(s, '.', sizeof s), ff(0, 0);
  printf("%d\n", T);
  for (int i = 0; i < 13; puts(""), i++)
    for (int j = 0; j < 15; j++) putchar(S[i][j]);
  return 0;
}