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;
char s[10][10];
const char *q = "BRWY";
int c[10], z[10], d[4][4];
bool b[10][10];
int id[10][10];
bool adj[10][10];
int A[22][22];
const int S = 21, T = 20;
bool u[22];
vector<pair<int, int> > zz;
bool dfs(int x) {
  u[x] = true;
  if (A[x][T]) {
    --A[x][T];
    ++A[T][x];
    return true;
  }
  int y0 = x < 10 ? 10 : 0, y1 = x >= 10 && x < 20 ? 10 : 20;
  for (int y(y0); y < y1; ++y) {
    if (A[x][y] && (y == T || !u[y] && dfs(y))) {
      --A[x][y];
      ++A[y][x];
      return true;
    }
  }
  return false;
}
int best = -1;
pair<int, int> p[100];
int m;
char dr[100][100], ans[100][100];
void put(int i0, int j0, int i1, int j1, int col) {
  int x = zz[col].first, y = zz[col].second;
  if ((s[i1][j1] == x) + (s[i0][j0] == y) >
      (s[i1][j1] == y) + (s[i0][j0] == x)) {
    swap(x, y);
  }
  dr[i0 * 2][j0 * 2] = q[x];
  dr[i1 * 2][j1 * 2] = q[y];
}
void check() {
  int r = 0;
  int d[10], e[10];
  m = 0;
  for (int i(0); i < 10; ++i) {
    d[i] = c[i];
    e[i] = z[i];
    for (; d[i] > 0 && e[i] > 0;) {
      r += 2;
      --d[i];
      --e[i];
      p[m++] = pair<int, int>(i, i);
    }
  }
  if (r + (28 - m) <= best) return;
  memset(A, 0, sizeof A);
  int flow = 0;
  for (int i(0); i < 10; ++i) {
    A[S][i] = d[i];
    A[i + 10][T] = e[i];
  }
  for (int i(0); i < 10; ++i)
    for (int j(0); j < 10; ++j) {
      if (adj[i][j]) {
        A[i][j + 10] = 28;
        for (; A[S][i] && A[i][j + 10] && A[j + 10][T];) {
          ++r;
          --A[S][i];
          --A[i][j + 10];
          --A[j + 10][T];
          ++A[T][j + 10];
          ++A[j + 10][i];
          ++A[i][S];
        }
      }
    }
  for (; memset(u, 0, sizeof u), dfs(S); ++r)
    ;
  if (r > best) {
    for (int i(0); i < 10; ++i)
      for (int j(0); j < 10; ++j) {
        for (int k(0); k < A[j + 10][i]; ++k) {
          --d[i];
          --e[j];
          p[m++] = pair<int, int>(j, i);
        }
      }
    for (int i(0); i < 10; ++i)
      for (int j(0); j < 10; ++j) {
        for (; d[i] > 0 && e[j] > 0;) {
          --d[i];
          --e[j];
          p[m++] = pair<int, int>(j, i);
        }
      }
    best = r;
    for (int i(0); i < 7; ++i)
      for (int j(0); j < 8; ++j) dr[i * 2][j * 2] = '.';
    for (int i(0); i < 7; ++i)
      for (int j(0); j < 8; ++j) {
        if (dr[i * 2][j * 2 + 1] == '-') {
          int x = id[s[i][j]][s[i][j + 1]];
          for (int l(0); l < m; ++l) {
            if (p[l].first == x) {
              put(i, j, i, j + 1, p[l].second);
              p[l] = p[--m];
              break;
            }
          }
        } else if (dr[i * 2 + 1][j * 2] == '|') {
          int x = id[s[i][j]][s[i + 1][j]];
          for (int l(0); l < m; ++l) {
            if (p[l].first == x) {
              put(i, j, i + 1, j, p[l].second);
              p[l] = p[--m];
              break;
            }
          }
        }
      }
    for (int i(0); i < 13; ++i)
      for (int j(0); j < 15; ++j) ans[i][j] = dr[i][j];
  }
}
void go(int i, int j) {
  if (i == 7) {
    check();
    return;
  }
  if (j == 8) {
    go(i + 1, 0);
    return;
  }
  if (!b[i][j]) {
    go(i, j + 1);
    return;
  }
  if (b[i][j + 1]) {
    b[i][j] = b[i][j + 1] = false;
    z[id[s[i][j]][s[i][j + 1]]]++;
    dr[i * 2][j * 2 + 1] = '-';
    go(i, j + 1);
    dr[i * 2][j * 2 + 1] = '.';
    z[id[s[i][j]][s[i][j + 1]]]--;
    b[i][j] = b[i][j + 1] = true;
  }
  if (b[i + 1][j]) {
    b[i][j] = b[i + 1][j] = false;
    z[id[s[i][j]][s[i + 1][j]]]++;
    dr[i * 2 + 1][j * 2] = '|';
    go(i, j + 1);
    dr[i * 2 + 1][j * 2] = '.';
    z[id[s[i][j]][s[i + 1][j]]]--;
    b[i][j] = b[i + 1][j] = true;
  }
}
int main() {
  for (int i(0); i < 7; ++i) {
    gets(s[i]);
    for (int j(0); j < 8; ++j) {
      b[i][j] = true;
      s[i][j] = find(q, q + 4, s[i][j]) - q;
    }
  }
  for (int i(0); i < 4; ++i)
    for (int j = 3; j >= i; --j) {
      id[i][j] = int((zz).size());
      id[j][i] = int((zz).size());
      cin >> c[int((zz).size())];
      zz.push_back(pair<int, int>(i, j));
    }
  for (int i(0); i < 10; ++i)
    for (int j(0); j < 10; ++j)
      if (zz[i].first == zz[j].first || zz[i].first == zz[j].second ||
          zz[i].second == zz[j].first || zz[i].second == zz[j].second) {
        adj[i][j] = true;
      }
  for (int i(0); i < 13; ++i)
    for (int j(0); j < 15; ++j) dr[i][j] = '.';
  go(0, 0);
  cout << best << endl;
  for (int i(0); i < 13; ++i) cout << ans[i] << endl;
  return 0;
}