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;
struct kraw {
  int a, cap;
};
vector<vector<int> > podzial(7, vector<int>(8, -1));
vector<int> ilNaObr(10, 0), ilMam(10, 0);
int nr = -1, mam = 0;
string tab[] = {"BB", "BR", "BW", "BY", "RR", "RW", "RY", "WW", "WY", "YY"};
vector<string> P(7);
vector<vector<kraw> > G(22);
const int INF = 100;
int odp = 57;
vector<vector<int> > odpPodzial;
vector<string> odpP1, odpP2;
vector<string> odpP(13);
const int base = 1000000007;
set<int> H;
int Szukaj(string a) {
  if (a[0] > a[1]) swap(a[0], a[1]);
  for (int i = 0; i < 10; ++i)
    if (tab[i] == a) return i;
}
int R(string a, string b) {
  return min((a[0] != b[0]) + (a[1] != b[1]), (a[0] != b[1]) + (a[1] != b[0]));
}
void Licz() {
  for (int i = 1; i <= 10; ++i) {
    G[0][i - 1].cap = ilNaObr[i - 1];
    G[i][10].cap = 0;
  }
  for (int i = 11; i <= 20; ++i) {
    G[i][0].cap = ilMam[i - 11];
    G[21][i - 11].cap = 0;
  }
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) {
      G[i][j - 11].cap = INF;
      G[j][i].cap = 0;
    }
  }
  vector<string> p1, p2;
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) {
      if (R(tab[i - 1], tab[j - 11]) == 0) {
        int m = min(ilNaObr[i - 1], ilMam[i - 1]);
        G[0][i - 1].cap -= m;
        G[j][0].cap -= m;
        for (int k = 0; k < m; ++k) {
          p1.push_back(tab[i - 1]);
          p2.push_back(tab[i - 1]);
        }
      }
      if (R(tab[i - 1], tab[j - 11]) == 2) {
        G[i][j - 11].cap = 0;
        G[j][i].cap = 0;
      }
    }
  }
  int flow = 0;
  while (true) {
    vector<int> pop(22, -1);
    queue<int> Q;
    Q.push(0);
    pop[0] = 0;
    while (!Q.empty()) {
      int akt = Q.front();
      Q.pop();
      for (int i = 0; i < G[akt].size(); ++i) {
        if (pop[G[akt][i].a] == -1 && G[akt][i].cap != 0) {
          pop[G[akt][i].a] = akt;
          Q.push(G[akt][i].a);
        }
      }
    }
    if (pop[21] == -1) break;
    vector<int> path;
    int akt = 21;
    while (akt != 0) {
      path.push_back(akt);
      akt = pop[akt];
    }
    path.push_back(0);
    reverse(path.begin(), path.end());
    int c = INF;
    for (int i = 0; i < (int)path.size() - 1; ++i)
      for (int j = 0; j < G[path[i]].size(); ++j)
        if (G[path[i]][j].a == path[i + 1]) c = min(c, G[path[i]][j].cap);
    for (int i = 0; i < (int)path.size() - 1; ++i) {
      for (int j = 0; j < G[path[i]].size(); ++j)
        if (G[path[i]][j].a == path[i + 1]) G[path[i]][j].cap -= c;
      for (int j = 0; j < G[path[i + 1]].size(); ++j)
        if (G[path[i + 1]][j].a == path[i]) G[path[i + 1]][j].cap += c;
    }
    flow += c;
  }
  for (int i = 11; i <= 20; ++i) {
    for (int j = 1; j <= 10; ++j) {
      int il = G[i][j].cap;
      for (int k = 0; k < il; ++k) {
        p1.push_back(tab[j - 1]);
        p2.push_back(tab[i - 11]);
      }
    }
  }
  int nowy = 2 * (28 - (int)p1.size()) + flow;
  if (nowy < odp) {
    odp = nowy;
    odpPodzial = podzial;
    odpP1 = p1;
    odpP2 = p2;
  }
}
void StworzG() {
  for (int i = 1; i <= 10; ++i) G[0].push_back({i, 0});
  for (int i = 1; i <= 10; ++i) {
    for (int j = 11; j <= 20; ++j) G[i].push_back({j, 0});
    G[i].push_back({0, 0});
  }
  for (int i = 11; i <= 20; ++i) {
    G[i].push_back({21, 0});
    for (int j = 1; j <= 10; ++j) G[i].push_back({j, 0});
  }
  for (int i = 11; i <= 20; ++i) G[21].push_back({i, 0});
}
void rec(int x, int y, int kier) {
  ++nr;
  podzial[x][y] = nr;
  if (kier == 0)
    podzial[x][y + 1] = nr;
  else
    podzial[x + 1][y] = nr;
  string para = "";
  para += P[x][y];
  if (kier == 0)
    para += P[x][y + 1];
  else
    para += P[x + 1][y];
  ++ilNaObr[Szukaj(para)];
  ++mam;
  if (mam == 28) {
    int h = 0;
    for (int i = 0; i < 10; ++i) h = h * base + ilNaObr[i];
    if (H.find(h) == H.end()) {
      Licz();
      H.insert(h);
    }
  }
  int nx = -1, ny = -1;
  for (int i = x; i < 7; ++i) {
    for (int j = 0; j < 8; ++j) {
      if (podzial[i][j] == -1) {
        nx = i;
        ny = j;
        break;
      }
    }
    if (nx != -1) break;
  }
  if (nx != -1) {
    if (ny + 1 < 8 && podzial[nx][ny + 1] == -1) rec(nx, ny, 0);
    if (nx + 1 < 7 && podzial[nx + 1][ny] == -1) rec(nx, ny, 1);
  }
  podzial[x][y] = -1;
  if (kier == 0)
    podzial[x][y + 1] = -1;
  else
    podzial[x + 1][y] = -1;
  --ilNaObr[Szukaj(para)];
  --nr;
  --mam;
}
void Wypisz() {
  multiset<string> wsz;
  for (int i = 0; i < 10; ++i)
    for (int j = 0; j < ilMam[i]; ++j) wsz.insert(tab[i]);
  cout << 56 - odp << endl;
  vector<bool> jest(odpP1.size(), true);
  for (int i = 0; i < 28; ++i) {
    int a = -1, b, c, d;
    for (int j = 0; j < 7; ++j) {
      for (int k = 0; k < 8; ++k) {
        if (odpPodzial[j][k] == i) {
          if (a == -1) {
            a = j;
            b = k;
          } else {
            c = j;
            d = k;
          }
        }
      }
    }
    string x = "";
    x += P[a][b];
    x += P[c][d];
    if (x[0] > x[1]) swap(x[0], x[1]);
    int nr = -1;
    for (int j = 0; j < odpP1.size(); ++j) {
      if (odpP1[j] == x && jest[j]) {
        nr = j;
        break;
      }
    }
    if (nr != -1) {
      if (R(x, odpP2[nr]) == 1) {
        if (P[a][b] == odpP2[nr][0]) P[c][d] = odpP2[nr][1];
        if (P[a][b] == odpP2[nr][1]) P[c][d] = odpP2[nr][0];
        if (P[c][d] == odpP2[nr][0]) P[a][b] = odpP2[nr][1];
        if (P[c][d] == odpP2[nr][1]) P[a][b] = odpP2[nr][0];
      }
      wsz.erase(wsz.find(odpP2[nr]));
      jest[nr] = false;
    } else {
      P[a][b] = 'Q';
      P[c][d] = 'Q';
    }
  }
  string t(15, '.');
  for (int i = 0; i < 13; ++i) odpP[i] = t;
  for (int i = 0; i < 7; ++i)
    for (int j = 0; j < 8; ++j) odpP[2 * i][2 * j] = P[i][j];
  for (int i = 0; i < 28; ++i) {
    int a = -1, b, c, d;
    for (int j = 0; j < 7; ++j) {
      for (int k = 0; k < 8; ++k) {
        if (odpPodzial[j][k] == i) {
          if (a == -1) {
            a = j;
            b = k;
          } else {
            c = j;
            d = k;
          }
        }
      }
    }
    if (odpP[2 * a][2 * b] == 'Q') {
      string x = *(wsz.begin());
      odpP[2 * a][2 * b] = x[0];
      odpP[2 * c][2 * d] = x[1];
      wsz.erase(wsz.find(x));
    }
    if (a == c)
      odpP[2 * a][2 * b + 1] = '-';
    else
      odpP[2 * a + 1][2 * b] = '|';
  }
  for (int i = 0; i < 13; ++i) cout << odpP[i] << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 7; ++i) cin >> P[i];
  cin >> ilMam[3] >> ilMam[2] >> ilMam[1] >> ilMam[0];
  cin >> ilMam[6] >> ilMam[5] >> ilMam[4];
  cin >> ilMam[8] >> ilMam[7];
  cin >> ilMam[9];
  StworzG();
  rec(0, 0, 0);
  rec(0, 0, 1);
  Wypisz();
  return 0;
}