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 max_flow_edge {
  long long int to, cap, rev;
};
vector<max_flow_edge> MAX_FLOW_E[25];
long long int same[10], base[10], best = -1;
char mp[10][10];
char ans[10 * 2][10 * 2];
set<vector<long long int> > s;
vector<long long int> now, best_vec;
vector<string> remain;
vector<string> one_vec[10];
map<pair<char, char>, long long int> con;
string color[] = {"BY", "BW", "BR", "BB", "RY", "RW", "RR", "WY", "WW", "YY"};
long long int max_flow(long long int s, long long int y);
void max_flow_add_edge(long long int from, long long int to, long long int cap);
void max_flow_init();
void recur(long long int x, long long int y, long long int mask) {
  if (y == 8) {
    recur(x + 1, 0, mask);
    return;
  }
  if (x == 7) {
    s.insert(now);
    return;
  }
  if (mask & 1) {
    recur(x, y + 1, mask / 2);
    return;
  }
  now[con[make_pair(mp[x][y], mp[x][y + 1])]]++;
  if (y + 1 < 8 && (mask & (1ll << (long long int)(1))) == 0)
    recur(x, y + 1, mask / 2 + 1);
  now[con[make_pair(mp[x][y], mp[x][y + 1])]]--;
  now[con[make_pair(mp[x][y], mp[x + 1][y])]]++;
  if (x + 1 < 7) recur(x, y + 1, mask / 2 + (1ll << (long long int)(8 - 1)));
  now[con[make_pair(mp[x][y], mp[x + 1][y])]]--;
}
long long int cal(vector<long long int> vec) {
  long long int res = 0;
  max_flow_init();
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    same[i] = min(base[i], vec[i]);
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    max_flow_add_edge(20, i, base[i] - same[i]);
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    max_flow_add_edge(10 + i, 21, vec[i] - same[i]);
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    for (long long int j = 0; j < ((long long int)(10)); ++j)
      if (color[i][0] == color[j][0] || color[i][0] == color[j][1] ||
          color[i][1] == color[j][0] || color[i][1] == color[j][1])
        max_flow_add_edge(i, j + 10, 100);
  for (long long int i = 0; i < ((long long int)(10)); ++i) res += same[i] * 2;
  return max_flow(20, 21) + res;
}
bool make(long long int x, long long int y) {
  if (x == 7) return true;
  if (y == 8) return make(x + 1, 0);
  if (ans[x * 2][y * 2] != '.') return make(x, y + 1);
  if (x + 1 != 7 && ans[x * 2 + 2][y * 2] == '.') {
    char c0 = mp[x][y], c1 = mp[x + 1][y];
    long long int num = con[make_pair(c0, c1)];
    if (best_vec[num] != 0) {
      ans[x * 2 + 1][y * 2] = '|';
      best_vec[num]--;
      if (same[num]) {
        same[num]--;
        ans[x * 2 + 0][y * 2] = c0;
        ans[x * 2 + 2][y * 2] = c1;
        if (make(x, y + 1)) return true;
        same[num]++;
      } else if (((long long int)(one_vec[num]).size())) {
        string str = one_vec[num].back();
        one_vec[num].pop_back();
        if (c0 != str[0] && c1 != str[1]) swap(str[0], str[1]);
        ans[x * 2 + 0][y * 2] = str[0];
        ans[x * 2 + 2][y * 2] = str[1];
        if (make(x, y + 1)) return true;
        one_vec[num].push_back(str);
      } else {
        string str = remain.back();
        remain.pop_back();
        ans[x * 2 + 0][y * 2] = str[0];
        ans[x * 2 + 2][y * 2] = str[1];
        if (make(x, y + 1)) return true;
        remain.push_back(str);
      }
      best_vec[num]++;
      ans[x * 2 + 0][y * 2] = ans[x * 2 + 1][y * 2] = ans[x * 2 + 2][y * 2] =
          '.';
    }
  }
  if (y + 1 != 8 && ans[x * 2][y * 2 + 2] == '.') {
    char c0 = mp[x][y], c1 = mp[x][y + 1];
    long long int num = con[make_pair(c0, c1)];
    if (best_vec[num] != 0) {
      best_vec[num]--;
      ans[x * 2][y * 2 + 1] = '-';
      if (same[num]) {
        same[num]--;
        ans[x * 2][y * 2 + 0] = c0;
        ans[x * 2][y * 2 + 2] = c1;
        if (make(x, y + 1)) return true;
        same[num]++;
      } else if (((long long int)(one_vec[num]).size())) {
        string str = one_vec[num].back();
        one_vec[num].pop_back();
        if (c0 != str[0] && c1 != str[1]) swap(str[0], str[1]);
        ans[x * 2][y * 2 + 0] = str[0];
        ans[x * 2][y * 2 + 2] = str[1];
        if (make(x, y + 1)) return true;
        one_vec[num].push_back(str);
      } else {
        string str = remain.back();
        remain.pop_back();
        ans[x * 2][y * 2 + 0] = str[0];
        ans[x * 2][y * 2 + 2] = str[1];
        if (make(x, y + 1)) return true;
        remain.push_back(str);
      }
      best_vec[num]++;
      ans[x * 2][y * 2 + 0] = ans[x * 2][y * 2 + 1] = ans[x * 2][y * 2 + 2] =
          '.';
    }
  }
  return false;
}
int main() {
  for (long long int i = 0; i < ((long long int)(7)); ++i) scanf("%s", mp[i]);
  now = vector<long long int>(10, 0);
  for (long long int i = 0; i < ((long long int)(10)); ++i) cin >> base[i];
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    con[make_pair(color[i][0], color[i][1])] = i;
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    con[make_pair(color[i][1], color[i][0])] = i;
  recur(0, 0, 0);
  for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); it++)
    if (best < cal(*it)) {
      best = cal(*it);
      best_vec = *it;
    }
  cout << cal(best_vec) << endl;
  for (long long int i = 0;
       i < ((long long int)(((long long int)(MAX_FLOW_E[20]).size()))); ++i)
    for (long long int j = 0; j < ((long long int)(MAX_FLOW_E[20][i].cap));
         ++j) {
      remain.push_back(color[MAX_FLOW_E[20][i].to]);
    }
  for (long long int i = 0; i < ((long long int)(10)); ++i)
    for (long long int j = 0;
         j < ((long long int)(((long long int)(MAX_FLOW_E[i + 10]).size())));
         ++j) {
      if (MAX_FLOW_E[i + 10][j].to == 21) continue;
      for (long long int k = 0;
           k < ((long long int)(MAX_FLOW_E[i + 10][j].cap)); ++k)
        one_vec[i].push_back(color[MAX_FLOW_E[i + 10][j].to]);
    }
  for (long long int i = 0; i < ((long long int)(10 * 2)); ++i)
    for (long long int j = 0; j < ((long long int)(10 * 2)); ++j)
      ans[i][j] = '.';
  make(0, 0);
  for (long long int i = 0; i < ((long long int)(13)); ++i) {
    for (long long int j = 0; j < ((long long int)(15)); ++j) cout << ans[i][j];
    cout << endl;
  }
}
long long int max_flow_iter[25];
long long int max_flow_level[25];
void max_flow_init() {
  for (long long int i = 0; i < ((long long int)(25)); ++i)
    MAX_FLOW_E[i].clear();
}
void max_flow_add_edge(long long int from, long long int to,
                       long long int cap) {
  max_flow_edge e0 = {to, cap, ((long long int)(MAX_FLOW_E[to]).size())};
  max_flow_edge e1 = {from, 0, ((long long int)(MAX_FLOW_E[from]).size())};
  MAX_FLOW_E[from].push_back(e0);
  MAX_FLOW_E[to].push_back(e1);
}
void max_flow_bfs(long long int s) {
  for (long long int i = 0; i < ((long long int)(25)); ++i)
    max_flow_level[i] = -1;
  max_flow_level[s] = 0;
  queue<long long int> q;
  q.push(s);
  while (((long long int)(q).size())) {
    long long int v = q.front();
    q.pop();
    for (long long int i = 0;
         i < ((long long int)(((long long int)(MAX_FLOW_E[v]).size()))); ++i) {
      max_flow_edge &e = MAX_FLOW_E[v][i];
      if (e.cap > 0 && max_flow_level[e.to] == -1) {
        max_flow_level[e.to] = max_flow_level[v] + 1;
        q.push(e.to);
      }
    }
  }
}
long long int max_flow_dfs(long long int pos, long long int g,
                           long long int f) {
  if (pos == g) return f;
  for (long long int &i = max_flow_iter[pos];
       i < ((long long int)(MAX_FLOW_E[pos]).size()); i++) {
    max_flow_edge &e = MAX_FLOW_E[pos][i];
    if (e.cap > 0 && max_flow_level[pos] < max_flow_level[e.to]) {
      long long int tmp = max_flow_dfs(e.to, g, min(f, e.cap));
      if (tmp > 0) {
        e.cap -= tmp;
        MAX_FLOW_E[e.to][e.rev].cap += tmp;
        return tmp;
      }
    }
  }
  return 0;
}
long long int max_flow(long long int s, long long int g) {
  if (s == g) {
    cout << "s==g at max_flow(li s,li g)" << endl;
    return -1;
  }
  long long int res = 0;
  while (true) {
    max_flow_bfs(s);
    if (max_flow_level[g] == -1) return res;
    for (long long int i = 0; i < ((long long int)(25)); ++i)
      max_flow_iter[i] = 0;
    long long int tmp;
    while ((tmp = max_flow_dfs(s, g, (1ll << (long long int)(62)))) > 0)
      res += tmp;
  }
  return -1;
}