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 N = 100005;
const int INF = 1 << 30;
int m, n, k, cnt, S, T, cc[N], c[N], pre[N], prd[N], tot;
vector<int> Eid[N];
struct Edge {
  int c, w, v;
} E[N];
void AddEdge(int x, int y, int c, int w) {
  E[++cnt].v = y;
  E[cnt].c = c;
  E[cnt].w = w;
  Eid[x].push_back(cnt);
  E[++cnt].v = x;
  E[cnt].c = -c;
  E[cnt].w = 0;
  Eid[y].push_back(cnt);
}
bool spfa() {
  static int Q[N * 2];
  static bool bo[N];
  int ql, qr;
  Q[ql = qr = 0] = S;
  fill(c, c + T + 1, INF);
  for (int i = 0; i <= T; i++) bo[i] = 0;
  cc[T] = 0;
  cc[S] = INF;
  c[S] = 0;
  while (ql <= qr) {
    int x = Q[ql++];
    bo[x] = 0;
    for (int i = 0; i < Eid[x].size(); i++) {
      const Edge &e = E[Eid[x][i]];
      if (e.w && e.c + c[x] < c[e.v]) {
        if (!bo[e.v]) Q[++qr] = e.v;
        bo[e.v] = 1;
        c[e.v] = e.c + c[x];
        cc[e.v] = min(e.w, cc[x]);
        pre[e.v] = x;
        prd[e.v] = Eid[x][i];
      }
    }
  }
  return cc[T] > 0;
}
int MaxFlow() {
  int flow = 0, cost = 0;
  while (spfa()) {
    int k = T;
    while (k != S) {
      E[prd[k]].w -= cc[T];
      E[prd[k] ^ 1].w += cc[T];
      k = pre[k];
    }
    flow += cc[T];
    cost += cc[T] * c[T];
  }
  return cost;
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
char color[4] = {'B', 'R', 'W', 'Y'}, s[10][10], Ans[20][20];
int x[10][10], y[10][10], w[20][20], id[5][5], eid[30][30];
int sum[4][4], num[4][4];
bool bo[10][10];
map<unsigned long long, bool> M;
int ans = INF;
int Get(int i, int j) {
  if (s[i][j] == 'B') return 0;
  if (s[i][j] == 'R') return 1;
  if (s[i][j] == 'W') return 2;
  return 3;
}
int cal(int i, int j, int k, int l) {
  int res = (i != k) + (j != l);
  res = min(res, (j != k) + (i != l));
  return res;
}
void check() {
  unsigned long long tmp = 0;
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= 7; i++) {
    for (int j = 1; j <= 8; j++) {
      int ii = Get(i, j), jj = Get(x[i][j], y[i][j]);
      num[min(ii, jj)][max(ii, jj)]++;
    }
  }
  for (int i = 0; i < 4; i++)
    for (int j = i; j < 4; j++) num[i][j] /= 2, tmp *= 31, tmp += num[i][j];
  if (M.count(tmp)) return;
  M[tmp] = true;
  cnt = -1;
  for (int i = 0; i <= 21; i++) Eid[i].clear();
  S = 0;
  T = 21;
  for (int i = 0; i < 4; i++)
    for (int j = i; j < 4; j++) AddEdge(S, id[i][j], 0, sum[i][j]);
  for (int i = 0; i < 4; i++)
    for (int j = i; j < 4; j++) AddEdge(id[i][j] + 10, T, 0, num[i][j]);
  for (int i = 1; i <= 10; i++)
    for (int j = 1; j <= 10; j++)
      AddEdge(i, j + 10, w[i][j], INF), eid[j][i] = cnt;
  int res = MaxFlow();
  if (res < ans) {
    ans = res;
    for (int i = 1; i <= 13; i++)
      for (int j = 1; j <= 15; j++) Ans[i][j] = '.';
    for (int i = 1; i <= 7; i++) {
      for (int j = 1; j <= 8; j++) {
        if (i * 8 + j > x[i][j] * 8 + y[i][j]) continue;
        int ii = Get(i, j), jj = Get(x[i][j], y[i][j]);
        if (ii > jj) swap(ii, jj);
        bool ok = 0;
        for (int k = 0; k < 4; k++) {
          if (ok) break;
          for (int l = k; l < 4; l++) {
            if (E[eid[id[ii][jj]][id[k][l]]].w) {
              ok = 1;
              E[eid[id[ii][jj]][id[k][l]]].w--;
              Ans[(i - 1) * 2 + 1][(j - 1) * 2 + 1] = color[k];
              Ans[(x[i][j] - 1) * 2 + 1][(y[i][j] - 1) * 2 + 1] = color[l];
              if ((Get(i, j) != k) + (Get(x[i][j], y[i][j]) != l) == 2)
                swap(Ans[(i - 1) * 2 + 1][(j - 1) * 2 + 1],
                     Ans[(x[i][j] - 1) * 2 + 1][(y[i][j] - 1) * 2 + 1]);
              if (i == x[i][j])
                Ans[(i - 1) * 2 + 1][(j - 1) * 2 + 2] = '-';
              else
                Ans[(i - 1) * 2 + 2][(j - 1) * 2 + 1] = '|';
              break;
            }
          }
        }
      }
    }
  }
}
void dfs(int i, int j) {
  if (j == 9) i++, j = 1;
  if (i == 7 && j == 8) {
    check();
    return;
  }
  if (bo[i][j]) {
    dfs(i, j + 1);
    return;
  }
  for (int k = 0; k < 4; k++) {
    int ii = i + dx[k], jj = j + dy[k];
    if (ii < 1 || ii > 7 || jj < 1 || jj > 8) continue;
    if (bo[ii][jj]) continue;
    x[ii][jj] = i;
    y[ii][jj] = j;
    x[i][j] = ii;
    y[i][j] = jj;
    bo[i][j] = bo[ii][jj] = 1;
    dfs(i, j + 1);
    bo[i][j] = bo[ii][jj] = 0;
  }
}
int main() {
  for (int i = 1; i <= 7; i++) scanf("%s", s[i] + 1);
  for (int i = 0; i < 4; i++)
    for (int j = 3; j >= i; j--) scanf("%d", &sum[i][j]);
  for (int i = 0; i < 4; i++)
    for (int j = i; j < 4; j++) id[i][j] = ++tot;
  for (int i = 0; i < 4; i++)
    for (int j = i; j < 4; j++)
      for (int k = 0; k < 4; k++)
        for (int l = k; l < 4; l++) w[id[i][j]][id[k][l]] = cal(i, j, k, l);
  dfs(1, 1);
  cout << 56 - ans << endl;
  for (int i = 1; i <= 13; i++) cout << Ans[i] + 1 << endl;
}