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 char col[] = "BRWY";
set<vector<int> > VIS;
vector<int> need(10, 0);
int S, T, best;
int F[22][22], u[22];
int A[10], a[10], C[10][10], fir[10], sec[10], num[4][4];
char ans[13][15], tmp[13][15];
int tr[7][8], td[7][8], s[7][8], vis[7][8];
void init() {
  S = 20;
  T = 21;
  int i, j;
  for (i = 0; i < (22); i++)
    for (j = 0; j < (22); j++) F[i][j] = 0;
}
int find(int x, int flow) {
  if (x == T) return flow;
  u[x] = 1;
  int i;
  for (i = 0; i < (22); i++)
    if (F[x][i] && !u[x]) {
      int tmp = find(i, min(flow, F[x][i]));
      F[x][i] -= tmp;
      F[i][x] += tmp;
      return tmp;
    }
  return 0;
}
void maxflow(int &ret) {
  memset(u, 0, sizeof u);
  int flow = find(S, 56);
  while (flow) {
    memset(u, 0, sizeof u);
    ret += flow;
    flow = find(S, 56);
  }
}
void solve() {
  int i, j, k, l;
  if (VIS.count(need)) return;
  VIS.insert(need);
  for (i = 0; i < (10); i++) A[i] = a[i];
  for (i = 0; i < (10); i++)
    for (j = 0; j < (10); j++) C[i][j] = 0;
  int ret = 0;
  for (i = 0; i < (10); i++) {
    C[i][i] = min(need[i], A[i]);
    ret += 2 * C[i][i];
  }
  if (ret / 2 + 28 <= best) return;
  init();
  for (i = 0; i < (10); i++) {
    if (A[i] > need[i]) F[S][i] += A[i] - need[i];
    if (A[i] < need[i]) F[i + 10][T] += need[i] - A[i];
  }
  for (i = 0; i < (10); i++)
    for (j = 0; j < (10); j++)
      if (fir[i] == fir[j] || fir[i] == sec[j] || sec[i] == fir[j] ||
          sec[i] == sec[j]) {
        k = min(F[S][i], F[j + 10][T]);
        F[S][i] -= k;
        F[j + 10][T] -= k;
        F[i][j + 10] += 56;
        ret += k;
        C[i][j] += k;
      }
  maxflow(ret);
  if (ret > best) {
    best = ret;
    for (i = 0; i < (13); i++)
      for (j = 0; j < (15); j++) ans[i][j] = tmp[i][j];
    for (i = 0; i < (10); i++)
      for (j = 0; j < (10); j++) C[i][j] += F[j + 10][i];
    for (i = 0; i < (7); i++)
      for (j = 0; j < (8); j++)
        if (tr[i][j]) {
          k = num[s[i][j]][s[i][j + 1]];
          for (l = 0; l < (10); l++)
            if (C[l][k]) {
              C[l][k]--;
              A[l]--;
              if (s[i][j] == fir[l] || s[i][j + 1] == sec[l]) {
                ans[i + i][j + j] = col[fir[l]];
                ans[i + i][j + j + 2] = col[sec[l]];
              } else {
                ans[i + i][j + j] = col[sec[l]];
                ans[i + i][j + j + 2] = col[fir[l]];
              }
              break;
            }
        }
    for (i = 0; i < (7); i++)
      for (j = 0; j < (8); j++)
        if (td[i][j]) {
          k = num[s[i][j]][s[i + 1][j]];
          for (l = 0; l < (10); l++)
            if (C[l][k]) {
              C[l][k]--;
              A[l]--;
              if (s[i][j] == fir[l] || s[i + 1][j] == sec[l]) {
                ans[i + i][j + j] = col[fir[l]];
                ans[i + i + 2][j + j] = col[sec[l]];
              } else {
                ans[i + i][j + j] = col[sec[l]];
                ans[i + i + 2][j + j] = col[fir[l]];
              }
              break;
            }
        }
    for (i = 0; i < (7); i++)
      for (j = 0; j < (8); j++)
        if (ans[i + i][j + j] == '.')
          for (l = 0; l < (10); l++)
            if (A[l]) {
              if (tr[i][j]) {
                A[l]--;
                ans[i + i][j + j] = col[fir[l]];
                ans[i + i][j + j + 2] = col[sec[l]];
              } else {
                A[l]--;
                ans[i + i][j + j] = col[fir[l]];
                ans[i + i + 2][j + j] = col[sec[l]];
              }
              break;
            }
  }
}
void dfs(int x, int y) {
  if (x == 7) {
    solve();
    return;
  }
  if (y == 8) {
    dfs(x + 1, 0);
    return;
  }
  if (vis[x][y]) {
    dfs(x, y + 1);
    return;
  }
  if (y < 7 && !vis[x][y + 1]) {
    vis[x][y] = vis[x][y + 1] = 1;
    need[num[s[x][y]][s[x][y + 1]]]++;
    tmp[x + x][y + y + 1] = '-';
    tr[x][y] = 1;
    dfs(x, y + 1);
    vis[x][y] = vis[x][y + 1] = 0;
    need[num[s[x][y]][s[x][y + 1]]]--;
    tmp[x + x][y + y + 1] = '.';
    tr[x][y] = 0;
  }
  if (x < 6 && !vis[x + 1][y]) {
    vis[x][y] = vis[x + 1][y] = 1;
    need[num[s[x][y]][s[x + 1][y]]]++;
    tmp[x + x + 1][y + y] = '|';
    td[x][y] = 1;
    dfs(x, y + 1);
    vis[x][y] = vis[x + 1][y] = 0;
    need[num[s[x][y]][s[x + 1][y]]]--;
    tmp[x + x + 1][y + y] = '.';
    td[x][y] = 0;
  }
}
int main() {
  int i, j;
  for (i = 0; i < (7); i++)
    for (j = 0; j < (8); j++) {
      char x;
      cin >> x;
      if (x == 'B') s[i][j] = 0;
      if (x == 'R') s[i][j] = 1;
      if (x == 'W') s[i][j] = 2;
      if (x == 'Y') s[i][j] = 3;
    }
  int tt = 0;
  for (i = 0; i < (4); i++)
    for (j = 3; j >= i; j--) {
      cin >> a[tt];
      fir[tt] = i;
      sec[tt] = j;
      num[i][j] = num[j][i] = tt++;
    }
  memset(tmp, '.', sizeof tmp);
  best = -1;
  dfs(0, 0);
  cout << best << endl;
  for (i = 0; i < (13); i++) {
    for (j = 0; j < (15); j++) cout << ans[i][j];
    cout << endl;
  }
}