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;
template <class A, class B>
A convert(B x) {
  stringstream ss;
  ss << x;
  A ret;
  ss >> ret;
  return ret;
}
const int oo = ~0u >> 2;
const double eps = 1e-10, pi = acos(-1);
const int ROW = 7, COL = 8, mp = 10, mc = 4 - 1, MAX_PTS = mp * 2 + 10,
          MAX_EDGES = ((MAX_PTS) * (MAX_PTS)) * 2, mo = 1000000007;
const int fx[8][2] = {{-1, 0},  {1, 0},  {0, -1}, {0, 1},
                      {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
const char tml[5] = "BRWY";
struct Edge {
  int y, f, c, l;
} E[MAX_EDGES];
int g[MAX_PTS], dis[MAX_PTS], fa[MAX_PTS], Q[MAX_PTS];
bool inq[MAX_PTS];
int tt, S(mp * 2 + 1), T(mp * 2 + 2);
int a[ROW][COL];
bool v[ROW][COL], hori[ROW][COL], vert[ROW][COL];
int req[mp], pil[mp], num[mc + 1][mc + 1];
pair<int, int> ps_ty[mp];
char Now[ROW * 2 + 1][COL * 2 + 1], Ans[ROW * 2 + 1][COL * 2 + 1],
    TMP[ROW * 2 + 1][COL * 2 + 1];
int Best(oo);
set<int> mem;
void add(int x, int y, int f, int c) {
  E[++tt].y = y, E[tt].f = f, E[tt].c = c, E[tt].l = g[x], g[x] = tt;
  E[++tt].y = x, E[tt].f = 0, E[tt].c = -c, E[tt].l = g[y], g[y] = tt;
}
int diff(int x, int y) {
  pair<int, int> l = make_pair(min(ps_ty[x].first, ps_ty[x].second),
                               max(ps_ty[x].first, ps_ty[x].second));
  pair<int, int> r = make_pair(min(ps_ty[y].first, ps_ty[y].second),
                               max(ps_ty[y].first, ps_ty[y].second));
  if (l.first == r.second || l.second == r.first) swap(l.first, l.second);
  int ret = (l.first != r.first) + (l.second != r.second);
  return ret;
}
void work() {
  int enc(0);
  for (int i = 0; i <= mp - 1; ++i) enc = ((long long)enc * 29 + pil[i]) % mo;
  if (mem.find(enc) != mem.end()) return;
  mem.insert(enc);
  memset(&g, 0, sizeof(g));
  ;
  tt = 1;
  for (int i = 0; i <= mp - 1; ++i) {
    add(S, i + 1, req[i], 0);
    add(i + mp + 1, T, pil[i], 0);
    for (int j = 0; j <= mp - 1; ++j) add(i + 1, j + mp + 1, oo, diff(i, j));
  }
  int Cost(0);
  do {
    for (int i = 0; i <= T; ++i) dis[i] = oo, inq[i] = 0;
    int l(0), r(0);
    Q[r = (r + 1) % MAX_PTS] = S, dis[S] = 0, inq[S] = 1;
    while (l != r) {
      int x = Q[l = (l + 1) % MAX_PTS];
      for (int i = g[x], y = E[i].y; i; i = E[i].l, y = E[i].y)
        if (E[i].f && dis[x] + E[i].c < dis[y]) {
          dis[y] = dis[x] + E[i].c, fa[y] = i;
          if (!inq[y]) inq[Q[r = (r + 1) % MAX_PTS] = y] = 1;
        }
      inq[x] = 0;
    }
    if (dis[T] == oo) break;
    int Aug = oo, x = T;
    while (x != S) Aug = min(Aug, E[fa[x]].f), x = E[fa[x] ^ 1].y;
    Cost += Aug * dis[T], x = T;
    while (x != S) E[fa[x]].f -= Aug, E[fa[x] ^ 1].f += Aug, x = E[fa[x] ^ 1].y;
  } while (1);
  if (Cost >= Best) return;
  int need[mp][mp], asn[mp], Cnt(0);
  for (int i = 0; i <= mp - 1; ++i) {
    asn[i] = 0;
    int SN(i * (mp + 2) * 2 + 7);
    for (int j = 0; j < mp; ++j, SN += 2) {
      need[j][i] = E[SN].f;
      if (E[SN].f) Cnt += E[SN].f * abs(E[SN].c);
    }
  }
  memcpy(&TMP, &Now, sizeof(Now));
  for (int i = 0; i <= ROW - 1; ++i)
    for (int j = 0; j <= COL - 1; ++j)
      if (hori[i][j] || vert[i][j]) {
        int x, y;
        if (hori[i][j])
          x = i, y = j + 1;
        else
          x = i + 1, y = j;
        int h(num[a[i][j]][a[x][y]]), t;
        if (need[h][h]) {
          --need[h][h], TMP[i * 2][j * 2] = tml[a[i][j]],
                                       TMP[x * 2][y * 2] = tml[a[x][y]];
          continue;
        }
        while (!need[h][asn[h]]) ++asn[h];
        --need[h][asn[h]],
            TMP[i * 2][j * 2] = tml[ps_ty[asn[h]].first],
                           TMP[x * 2][y * 2] = tml[ps_ty[asn[h]].second];
        int D = (ps_ty[asn[h]].first != a[i][j]) +
                (ps_ty[asn[h]].second != a[x][y]);
        if (D != diff(h, asn[h]))
          TMP[i * 2][j * 2] = tml[ps_ty[asn[h]].second],
                         TMP[x * 2][y * 2] = tml[ps_ty[asn[h]].first];
      }
  memcpy(&Ans, &TMP, sizeof(TMP));
  Best = Cost;
}
void dfs(int x, int y) {
  if (x == ROW) {
    work();
    return;
  }
  int nx = y == (COL - 1) ? x + 1 : x, ny = (y + 1) % COL;
  if (v[x][y]) {
    dfs(nx, ny);
    return;
  }
  if (y + 1 < COL && !v[x][y + 1]) {
    v[x][y] = v[x][y + 1] = 1, Now[x * 2][y * 2 + 1] = '-', hori[x][y] = 1;
    ++pil[num[a[x][y]][a[x][y + 1]]];
    dfs(nx, ny);
    --pil[num[a[x][y]][a[x][y + 1]]];
    v[x][y] = v[x][y + 1] = 0, Now[x * 2][y * 2 + 1] = '.', hori[x][y] = 0;
  }
  if (x + 1 < ROW && !v[x + 1][y]) {
    v[x][y] = v[x + 1][y] = 1, Now[x * 2 + 1][y * 2] = '|', vert[x][y] = 1;
    ++pil[num[a[x][y]][a[x + 1][y]]];
    dfs(nx, ny);
    --pil[num[a[x][y]][a[x + 1][y]]];
    v[x][y] = v[x + 1][y] = 0, Now[x * 2 + 1][y * 2] = '.', vert[x][y] = 0;
  }
}
int main() {
  for (int i = 0; i < ROW; ++i, scanf("\n"))
    for (int j = 0; j <= COL - 1; ++j) {
      char ch;
      scanf("%c", &ch);
      a[i][j] = strchr(tml, ch) - tml;
    }
  int tt(0);
  for (int i = 0; i <= mc; ++i)
    for (int j = mc; j >= i; --j) {
      num[i][j] = num[j][i] = tt;
      ps_ty[tt++] = make_pair(i, j);
    }
  for (int i = 0; i <= tt - 1; ++i) scanf("%d", req + i);
  memset(&Now, '.', sizeof(Now));
  ;
  memset(&v, 0, sizeof(v));
  ;
  memset(&pil, 0, sizeof(pil));
  ;
  memset(&hori, 0, sizeof(hori));
  ;
  memset(&vert, 0, sizeof(vert));
  ;
  mem.clear();
  dfs(0, 0);
  printf("%d\n", ROW * COL - Best);
  for (int i = 0; i < ROW * 2 - 1; printf("\n"), ++i)
    for (int j = 0; j <= COL * 2 - 2; ++j) printf("%c", Ans[i][j]);
}