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;
vector<int> st;
set<vector<int> > hsh;
char col[5] = "BRWY";
int g[25][25];
char board[10][10];
char fin[20][20], tmp[20][20];
int a[10][10], num[10][10], cnt[10], tc[10], x[10], y[10], tot;
int ans = 0, S = 21, T = 22;
int vis[10][10];
int R[10][10], D[10][10], C[10][10], u[25];
inline int MAP(char t) {
  return t == 'B' ? 0 : t == 'R' ? 1 : t == 'W' ? 2 : 3;
}
int Dfs(int t, int flow) {
  if (t == T) return flow;
  u[t] = 1;
  for (int i = 0; i < 25; i++)
    if (g[t][i] && !u[i]) {
      int tmp = Dfs(i, min(flow, g[t][i]));
      g[t][i] -= tmp;
      g[i][t] += tmp;
      return tmp;
    }
  return 0;
}
int maxFlow() {
  int res = 0;
  while (1) {
    memset(u, 0, sizeof(u));
    int dt = Dfs(S, 56);
    if (!dt) break;
    res += dt;
  }
  return res;
}
void deal() {
  int res = 0;
  if (hsh.count(st)) return;
  hsh.insert(st);
  memcpy(tc, cnt, sizeof(tc));
  memset(C, 0, sizeof(C));
  for (int i = 0; i < 10; i++) C[i][i] = min(st[i], tc[i]), res += 2 * C[i][i];
  if (res / 2 + 28 <= ans) return;
  memset(g, 0, sizeof(g));
  for (int i = 0; i < 10; i++)
    tc[i] > st[i] ? (g[S][i] = tc[i] - st[i]) : (g[i + 10][T] = st[i] - tc[i]);
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (x[i] == x[j] || x[i] == y[j] || y[i] == x[j] || y[i] == y[j]) {
        int k = min(g[S][i], g[j + 10][T]);
        g[S][i] -= k;
        g[j + 10][T] -= k;
        g[i][j + 10] += 56;
        res += k;
        C[i][j] += k;
      }
  res += maxFlow();
  if (res <= ans) return;
  ans = res;
  memcpy(fin, tmp, sizeof(tmp));
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++) C[i][j] += g[j + 10][i];
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (R[i][j]) {
        int k = num[a[i][j]][a[i][j + 1]];
        for (int l = 0; l < 10; l++)
          if (C[l][k]) {
            C[l][k]--;
            tc[l]--;
            if (a[i][j] == x[l] || a[i][j + 1] == y[l])
              fin[i + i][j + j] = col[x[l]], fin[i + i][j + j + 2] = col[y[l]];
            else
              fin[i + i][j + j] = col[y[l]], fin[i + i][j + j + 2] = col[x[l]];
            break;
          }
      }
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (D[i][j]) {
        int k = num[a[i][j]][a[i + 1][j]];
        for (int l = 0; l < 10; l++)
          if (C[l][k]) {
            C[l][k]--;
            tc[l]--;
            if (a[i][j] == x[l] || a[i + 1][j] == y[l])
              fin[i + i][j + j] = col[x[l]], fin[i + i + 2][j + j] = col[y[l]];
            else
              fin[i + i][j + j] = col[y[l]], fin[i + i + 2][j + j] = col[x[l]];
            break;
          }
      }
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++)
      if (fin[i + i][j + j] == '.')
        for (int l = 0; l < 10; l++)
          if (tc[l]) {
            if (R[i][j])
              tc[l]--, fin[i + i][j + j] = col[x[l]],
                                      fin[i + i][j + j + 2] = col[y[l]];
            else
              tc[l]--, fin[i + i][j + j] = col[x[l]],
                                      fin[i + i + 2][j + j] = col[y[l]];
            break;
          }
}
void dfs(int x, int y) {
  if (x >= 7)
    deal();
  else if (y >= 8)
    dfs(x + 1, 0);
  else if (vis[x][y])
    dfs(x, y + 1);
  else {
    if (x < 6 && !vis[x + 1][y]) {
      vis[x][y] = vis[x + 1][y] = 1;
      st[num[a[x][y]][a[x + 1][y]]]++;
      tmp[x + x + 1][y + y] = '|';
      D[x][y] = 1;
      dfs(x, y + 1);
      D[x][y] = 0;
      tmp[x + x + 1][y + y] = '.';
      st[num[a[x][y]][a[x + 1][y]]]--;
      vis[x][y] = vis[x + 1][y] = 0;
    }
    if (y < 7 && !vis[x][y + 1]) {
      vis[x][y] = vis[x][y + 1] = 1;
      st[num[a[x][y]][a[x][y + 1]]]++;
      tmp[x + x][y + y + 1] = '-';
      R[x][y] = 1;
      dfs(x, y + 1);
      R[x][y] = 0;
      st[num[a[x][y]][a[x][y + 1]]]--;
      tmp[x + x][y + y + 1] = '.';
      vis[x][y] = vis[x][y + 1] = 0;
    }
  }
}
int main() {
  for (int i = 0; i < 7; i++) scanf("%s", board[i]);
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 8; j++) a[i][j] = MAP(board[i][j]);
  for (int i = 0; i < 4; i++)
    for (int j = 3; j >= i; j--) {
      st.push_back(0);
      scanf("%d", &cnt[tot]), x[tot] = i, y[tot] = j;
      num[i][j] = num[j][i] = tot++;
    }
  memset(tmp, '.', sizeof(tmp));
  ans = -1;
  dfs(0, 0);
  printf("%d\n", ans);
  for (int i = 0; i < 13; i++) {
    for (int j = 0; j < 15; j++) putchar(fin[i][j]);
    puts("");
  }
  return 0;
}