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 P[4] = {'B', 'R', 'W', 'Y'};
struct ww {
  int x, y;
};
struct w {
  ww a, b;
  int c, d, e;
} c[100], q[20][20][50];
int i, j, k, n, m, an, S, T, t, num, ge;
int a[100][100], h[200], f[100][100], b[100][100], len[100][100], id[100][100],
    st[100][100], d[100][100], ba[1000], bb[1000], head[1000], nxt[1000],
    F[1000], g[1000], gg[1000];
char p[100], s[100][100], re[100][100];
set<unsigned long long> Set;
inline void add(int x, int y, int z) {
  ba[++t] = y, bb[t] = z, nxt[t] = head[x], head[x] = t;
  ba[++t] = x, bb[t] = 0, nxt[t] = head[y], head[y] = t;
}
inline bool bfs() {
  int l, r, v;
  g[l = r = 1] = S;
  gg[S] = 0;
  F[S] = ++num;
  for (; l <= r; l++)
    for (v = head[g[l]]; v; v = nxt[v]) {
      int A = ba[v];
      if (bb[v] && F[A] != num) {
        F[A] = num;
        gg[A] = gg[g[l]] + 1;
        g[++r] = A;
        if (A == T) return 1;
      }
    }
  return 0;
}
int Dfs(int x, int y) {
  if (x == T) return y;
  int v, w = 0, re;
  for (v = head[x]; v && w < y; v = nxt[v]) {
    int A = ba[v];
    if (bb[v] && gg[A] == gg[x] + 1 && F[A] == num &&
        (re = Dfs(A, min(bb[v], y - w))))
      bb[v] -= re, bb[v ^ 1] += re, w += re;
  }
  if (!w) gg[x] = 0;
  return w;
}
inline void Print(ww A, int B) { re[2 * A.x - 1][2 * A.y - 1] = P[B]; }
inline void print(w A, int x, int y) {
  if (A.e) swap(A.a, A.b), swap(A.c, A.d);
  if (x != A.c && y != A.d) swap(x, y);
  Print(A.a, x);
  Print(A.b, y);
}
inline void work() {
  int i, j, u, r;
  for (i = 0; i <= 3; i++)
    for (j = i; j <= 3; j++) len[i][j] = 0;
  for (i = 1; i <= ge; i++) {
    w A = c[i];
    q[A.c][A.d][++len[A.c][A.d]] = A;
  }
  unsigned long long hash = 0;
  for (i = 0; i <= 3; i++)
    for (j = i; j <= 3; j++) hash = hash * 97 + len[i][j];
  if (Set.count(hash)) return;
  Set.insert(hash);
  S = 21, T = 22;
  for (i = 1; i <= T; i++) head[i] = 0;
  t = 1;
  int sum = 0;
  for (i = 0; i <= 3; i++)
    for (j = i; j <= 3; j++) {
      st[i][j] = min(len[i][j], b[i][j]);
      d[i][j] = b[i][j] - st[i][j];
      sum += st[i][j] * 2;
      if (len[i][j] > b[i][j]) add(S, id[i][j], len[i][j] - b[i][j]);
      if (len[i][j] < b[i][j]) add(id[i][j] + 10, T, b[i][j] - len[i][j]);
      for (u = 0; u <= 3; u++)
        for (r = u; r <= 3; r++) {
          if (i == u && j == r) continue;
          int A = i == u || i == r || j == u || j == r;
          if (A) add(id[i][j], id[u][r] + 10, 1000);
        }
    }
  for (; bfs(); sum += Dfs(S, 1000))
    ;
  if (sum > an) {
    an = sum;
    memcpy(re, s, sizeof(re));
    for (i = 0; i <= 3; i++)
      for (j = 0; j <= 3; j++) {
        for (k = 1; k <= st[i][j]; k++) {
          w B = q[i][j][k];
          print(B, i, j);
        }
        int B = id[i][j], v;
        for (v = head[B]; v; v = nxt[v]) {
          int C = ba[v];
          if (C <= 10 || C > 20 || bb[v] == 1000) continue;
          for (u = 0; u <= 3; u++)
            for (r = u; r <= 3; r++)
              if (id[u][r] + 10 == C) goto yy1;
        yy1:;
          int o;
          for (o = bb[v] + 1; o <= 1000; o++)
            print(q[i][j][++st[i][j]], u, r), d[u][r]--;
        }
      }
    for (i = 0; i <= 3; i++)
      for (j = i; j <= 3; j++)
        for (; st[i][j] < len[i][j];) {
          int A = ++st[i][j];
          for (u = 0; u <= 3; u++)
            for (r = u; r <= 3; r++)
              if (d[u][r]) goto yy2;
        yy2:;
          print(q[i][j][A], u, r);
          d[u][r]--;
        }
  }
}
inline void get(int A, int B, ww C, ww D) {
  int a = 0;
  if (A > B) swap(A, B), swap(C, D), a = 1;
  c[++ge] = (w){C, D, A, B, a};
}
void dfs(int x, int y) {
  if (x > 7) {
    work();
    return;
  }
  if (y > 8) {
    dfs(x + 1, 1);
    return;
  }
  if (f[x][y]) {
    dfs(x, y + 1);
    return;
  }
  if (x < 7) {
    f[x][y] = f[x + 1][y] = 1;
    get(a[x][y], a[x + 1][y], (ww){x, y}, (ww){x + 1, y});
    s[2 * x][2 * y - 1] = '|';
    dfs(x, y + 1);
    s[2 * x][2 * y - 1] = '.';
    ge--;
    f[x][y] = f[x + 1][y] = 0;
  }
  if (y < 8 && !f[x][y + 1]) {
    f[x][y] = f[x][y + 1] = 1;
    get(a[x][y], a[x][y + 1], (ww){x, y}, (ww){x, y + 1});
    s[2 * x - 1][2 * y] = '-';
    dfs(x, y + 1);
    s[2 * x - 1][2 * y] = '.';
    ge--;
    f[x][y] = f[x][y + 1] = 0;
  }
}
int main() {
  h['B'] = 0, h['R'] = 1, h['W'] = 2, h['Y'] = 3;
  for (i = 1; i <= 7; i++) {
    scanf("%s", p + 1);
    for (j = 1; j <= 8; j++) a[i][j] = h[p[j]];
  }
  for (i = 0; i <= 3; i++)
    for (j = 3; j >= i; j--) scanf("%d", &b[i][j]);
  k = 0;
  for (i = 0; i <= 3; i++)
    for (j = i; j <= 3; j++) id[i][j] = ++k;
  an = -1;
  memset(s, '.', sizeof(s));
  dfs(1, 1);
  printf("%d\n", an);
  for (i = 1; i <= 13; i++) {
    for (j = 1; j <= 15; j++) printf("%c", re[i][j]);
    printf("\n");
  }
  return 0;
}