Boboniu defines BN-string as a string s of characters 'B' and 'N'.

You can perform the following operations on the BN-string s:

  * Remove a character of s. 
  * Remove a substring "BN" or "NB" of s. 
  * Add a character 'B' or 'N' to the end of s. 
  * Add a string "BN" or "NB" to the end of s. 



Note that a string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Boboniu thinks that BN-strings s and t are similar if and only if:

  * |s|=|t|. 
  * There exists a permutation p_1, p_2, …, p_{|s|} such that for all i (1≤ i≤ |s|), s_{p_i}=t_i. 



Boboniu also defines dist(s,t), the distance between s and t, as the minimum number of operations that makes s similar to t.

Now Boboniu gives you n non-empty BN-strings s_1,s_2,…, s_n and asks you to find a non-empty BN-string t such that the maximum distance to string s is minimized, i.e. you need to minimize max_{i=1}^n dist(s_i,t).

Input

The first line contains a single integer n (1≤ n≤ 3⋅ 10^5).

Each of the next n lines contains a string s_i (1≤ |s_i| ≤ 5⋅ 10^5). It is guaranteed that s_i only contains 'B' and 'N'. The sum of |s_i| does not exceed 5⋅ 10^5.

Output

In the first line, print the minimum max_{i=1}^n dist(s_i,t).

In the second line, print the suitable t.

If there are several possible t's, you can print any.

Examples

Input


3
B
N
BN


Output


1
BN


Input


10
N
BBBBBB
BNNNBBNBB
NNNNBNBNNBNNNBBN
NBNBN
NNNNNN
BNBNBNBBBBNNNNBBBBNNBBNBNBBNBBBBBBBB
NNNNBN
NBBBBBBBB
NNNNNN


Output


12
BBBBBBBBBBBBNNNNNNNNNNNN


Input


8
NNN
NNN
BBNNBBBN
NNNBNN
B
NNN
NNNNBNN
NNNNNNNNNNNNNNNBNNNNNNNBNB


Output


12
BBBBNNNNNNNNNNNN


Input


3
BNNNBNNNNBNBBNNNBBNNNNBBBBNNBBBBBBNBBBBBNBBBNNBBBNBNBBBN
BBBNBBBBNNNNNBBNBBBNNNBB
BBBBBBBBBBBBBBNBBBBBNBBBBBNBBBBNB


Output


12
BBBBBBBBBBBBBBBBBBBBBBBBBBNNNNNNNNNNNN

Note

In the first example dist(B,BN)=dist(N,BN)=1, dist(BN,BN)=0. So the maximum distance is 1.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Iterator;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
import java.util.function.IntFunction;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CBoboniuAndString solver = new CBoboniuAndString();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CBoboniuAndString {
        int[][] pts;
        int limit = (int) 5e5;
        IntegerMinQueue topSelfMinQueue = new IntegerMinQueue(limit + 1, IntegerComparator.NATURE_ORDER);
        IntegerMinQueue topSolidMinQueue = new IntegerMinQueue(limit + 1, IntegerComparator.NATURE_ORDER);
        IntegerMinQueue botSelfMinQueue = new IntegerMinQueue(limit + 1, IntegerComparator.REVERSE_ORDER);
        IntegerMinQueue botSolidMinQueue = new IntegerMinQueue(limit + 1, IntegerComparator.REVERSE_ORDER);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            pts = new int[n][2];
            char[] s = new char[(int) 1e6];
            for (int i = 0; i < n; i++) {
                int len = in.readString(s, 0);
                for (int j = 0; j < len; j++) {
                    if (s[j] == 'B') {
                        pts[i][0]++;
                    } else {
                        pts[i][1]++;
                    }
                }
            }
            Arrays.sort(pts, (a, b) -> Integer.compare(a[0], b[0]));

            IntBinarySearch ibs = new IntBinarySearch() {

                public boolean check(int mid) {
                    return CBoboniuAndString.this.check(mid) != null;
                }
            };

            int ans = ibs.binarySearch(0, limit);
            check(ans);
            out.println(ans);
            int[] t = check(ans);

            for (int i = 0; i < t[0]; i++) {
                out.append('B');
            }
            for (int i = 0; i < t[1]; i++) {
                out.append('N');
            }
        }

        public int[] check(int mid) {
            topSelfMinQueue.reset();
            topSolidMinQueue.reset();
            botSelfMinQueue.reset();
            botSolidMinQueue.reset();

            int l = pts[pts.length - 1][0] - mid;
            int r = pts[0][0] + mid;

            Range2DequeAdapter<int[]> dq1 = new Range2DequeAdapter<>(i -> pts[i], 0, pts.length - 1);
            Range2DequeAdapter<int[]> dq2 = new Range2DequeAdapter<>(i -> pts[i], 0, pts.length - 1);
            for (int i = 0; i <= limit; i++) {
                while (!dq1.isEmpty() && dq1.peekFirst()[0] - mid <= i) {
                    int[] head = dq1.removeFirst();
                    int y = head[1] + mid;
                    int x = head[0];
                    topSelfMinQueue.addLast(y - x);
                    botSolidMinQueue.addLast(head[1] - mid);
                }
                while (!dq2.isEmpty() && dq2.peekFirst()[0] <= i) {
                    topSelfMinQueue.removeFirst();
                    botSolidMinQueue.removeFirst();

                    int[] head = dq2.removeFirst();
                    int y = head[1] - mid;
                    int x = head[0];
                    botSelfMinQueue.addLast(y - x);
                    topSolidMinQueue.addLast(head[1] + mid);
                }
                if (l <= i && i <= r) {
                    int top = Math.min(topSelfMinQueue.min() + i, topSolidMinQueue.min());
                    int bot = Math.max(botSelfMinQueue.min() + i, botSolidMinQueue.min());
                    bot = Math.max(bot, 0);
                    if (bot <= top && (i + top > 0)) {
                        return new int[]{i, top};
                    }
                }
            }

            return null;
        }

    }

    static class Range2DequeAdapter<T> implements SimplifiedDeque<T> {
        IntFunction<T> data;
        int l;
        int r;

        public Range2DequeAdapter(IntFunction<T> data, int l, int r) {
            this.data = data;
            this.l = l;
            this.r = r;
        }

        public boolean isEmpty() {
            return l > r;
        }

        public T peekFirst() {
            return data.apply(l);
        }

        public T removeFirst() {
            return data.apply(l++);
        }

        public Iterator<T> iterator() {
            return new Iterator<T>() {
                int iter = l;


                public boolean hasNext() {
                    return iter <= r;
                }


                public T next() {
                    return data.apply(iter++);
                }
            };
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static interface IntegerComparator {
        public static final IntegerComparator NATURE_ORDER = (a, b) -> Integer.compare(a, b);
        public static final IntegerComparator REVERSE_ORDER = (a, b) -> Integer.compare(b, a);

        public int compare(int a, int b);

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int floorAverage(int x, int y) {
            return (x & y) + ((x ^ y) >> 1);
        }

    }

    static abstract class IntBinarySearch {
        public abstract boolean check(int mid);

        public int binarySearch(int l, int r) {
            if (l > r) {
                throw new IllegalArgumentException();
            }
            while (l < r) {
                int mid = DigitUtils.floorAverage(l, r);
                if (check(mid)) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return l;
        }

    }

    static interface IntegerDeque extends IntegerStack {
    }

    static interface SimplifiedStack<T> extends Iterable<T> {
    }

    static class IntegerDequeImpl implements IntegerDeque {
        private int[] data;
        private int bpos;
        private int epos;
        private static final int[] EMPTY = new int[0];
        private int n;

        public IntegerDequeImpl(int cap) {
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
            bpos = 0;
            epos = 0;
            n = cap;
        }

        private void expandSpace(int len) {
            while (n < len) {
                n = Math.max(n + 10, n * 2);
            }
            int[] newData = new int[n];
            if (bpos <= epos) {
                if (bpos < epos) {
                    System.arraycopy(data, bpos, newData, 0, epos - bpos);
                }
            } else {
                System.arraycopy(data, bpos, newData, 0, data.length - bpos);
                System.arraycopy(data, 0, newData, data.length - bpos, epos);
            }
            epos = size();
            bpos = 0;
            data = newData;
        }

        public IntegerIterator iterator() {
            return new IntegerIterator() {
                int index = bpos;


                public boolean hasNext() {
                    return index != epos;
                }


                public int next() {
                    int ans = data[index];
                    index = IntegerDequeImpl.this.next(index);
                    return ans;
                }
            };
        }

        public int removeFirst() {
            int ans = data[bpos];
            bpos = next(bpos);
            return ans;
        }

        public int removeLast() {
            int ans = data[last(epos)];
            epos = last(epos);
            return ans;
        }

        public void addLast(int x) {
            ensureMore();
            data[epos] = x;
            epos = next(epos);
        }

        public int peekFirst() {
            return data[bpos];
        }

        public int peekLast() {
            return data[last(epos)];
        }

        public void clear() {
            bpos = epos = 0;
        }

        private int last(int x) {
            return (x == 0 ? n : x) - 1;
        }

        private int next(int x) {
            return x + 1 >= n ? 0 : x + 1;
        }

        private void ensureMore() {
            if (next(epos) == bpos) {
                expandSpace(n + 1);
            }
        }

        public int size() {
            int ans = epos - bpos;
            if (ans < 0) {
                ans += data.length;
            }
            return ans;
        }

        public boolean isEmpty() {
            return bpos == epos;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
                builder.append(iterator.next()).append(' ');
            }
            return builder.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

    }

    static class IntegerMinQueue {
        IntegerDequeImpl minQueue;
        IntegerDequeImpl data;
        IntegerComparator comparator;

        public IntegerMinQueue(int cap, IntegerComparator comparator) {
            minQueue = new IntegerDequeImpl(cap);
            data = new IntegerDequeImpl(cap);
            this.comparator = comparator;
        }

        public void reset() {
            minQueue.clear();
            data.clear();
        }

        public void addLast(int val) {
            data.addLast(val);
            while (!minQueue.isEmpty() && comparator.compare(minQueue.peekLast(), val) > 0) {
                minQueue.removeLast();
            }
            minQueue.addLast(val);
        }

        public int removeFirst() {
            int val = data.removeFirst();
            if (minQueue.peekFirst() == val) {
                minQueue.removeFirst();
            }
            return val;
        }

        public int min() {
            return minQueue.peekFirst();
        }

    }

    static interface IntegerStack {
    }

    static interface SimplifiedDeque<T> extends SimplifiedStack<T> {
    }

    static interface IntegerIterator {
        boolean hasNext();

        int next();

    }
}

