import java.util.*;

public class Main {
    public static final int MAX_WEIGHT = 1_000_000_000;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] d = new int[n];
        int[] toMin = new int[n];
        int[] curMin = new int[n];
        int[] edgeMin = new int[n];
        Arrays.fill(curMin, Integer.MAX_VALUE);

        for (int i = 0; i < n; i++) {
            d[i] = scanner.nextInt();
        }

        int u, v;
        for (int i = 0; i < m; i++) {
            u = scanner.nextInt()-1;
            v = scanner.nextInt()-1;
            if(curMin[u]>d[v]){
                toMin[u] = v;
                curMin[u] = d[v];
                edgeMin[u] = i;
            }
            if(curMin[v]>d[u]){
                toMin[v] = u;
                curMin[v] = d[u];
                edgeMin[v] = i;
            }
        }

        for (int i = 0; i < n; i++) {
            if(d[i]<curMin[i]){
                System.out.println(-1);
                return;
            }
        }


        Pair<Boolean[], Integer[]> result = bichrome(d, toMin, edgeMin, m);
        if (result != null) {
            Boolean[] colors = result.getFirst();
            for (boolean color: colors) {
                System.out.print(color ? "B" : "W");
            }
            System.out.println();
            for (int w : result.second) {
                System.out.println(w);
            }
        } else {
            System.out.println(-1);
        }
    }

    public static Pair<Boolean[], Integer[]> bichrome(int[] d, int[] toMin, int[] edgeMin, int m) {
        int n = toMin.length;
        Boolean[] nodeColors = new Boolean[n];
        Integer[] edgeWeights = new Integer[m];
        Stack<Integer> stack = new Stack<>();

        for (int i = 0; i < n; i++) {
            if(nodeColors[i]!=null) continue;
            stack.push(i);
            while (!stack.isEmpty()){
                Integer peeked = stack.peek();
                if(nodeColors[toMin[peeked]]!=null){
                    if(d[peeked]>=d[toMin[peeked]]){
                        nodeColors[peeked]=!nodeColors[toMin[peeked]];
                        edgeWeights[edgeMin[peeked]] = d[peeked];
                        stack.pop();
                    }else{
                        return null;
                    }
                }else{
                    if(d[toMin[peeked]]==d[peeked]){
                        toMin[toMin[peeked]] = peeked;
                        nodeColors[toMin[peeked]] = true;
                        nodeColors[peeked] = false;
                        edgeWeights[edgeMin[peeked]] = d[peeked];
                        stack.pop();
                    }else{
                        stack.push(toMin[peeked]);
                    }
                }
            }
        }


//        for (Map.Entry<Integer, Set<Integer>> setEntry : treeMap.entrySet()) {
//            Set<Integer> entryValue = setEntry.getValue();
//            Integer minWeight = setEntry.getKey();
//            for (Integer node : entryValue) {
//                if (nodeColors[node] != null) continue;
//                Integer toMinForNode = toMin[node];
//                if (nodeColors[toMinForNode] != null) {
//                    nodeColors[node] = !nodeColors[toMinForNode];
//                    edgeWeights[edgeMin[node]] = minWeight;
//                    continue;
//                }
//                if (entryValue.contains(toMinForNode)) {
//                    //нужно покрасить два
//                    nodeColors[node] = true;
//                    nodeColors[toMinForNode] = false;
//                    edgeWeights[edgeMin[node]] = minWeight;
//                    continue;
//                }
//                return null;
//            }
//        }


        for (int i = 0; i < edgeWeights.length; i++) {
            if (edgeWeights[i] == null) edgeWeights[i] = MAX_WEIGHT;
        }
        return new Pair<>(nodeColors, edgeWeights);
    }

    public static class Pair<A, B> {
        private A first;
        private B second;

        public Pair(A first, B second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            return first.equals(pair.first) &&
                    second.equals(pair.second);
        }

        @Override
        public int hashCode() {
            return Objects.hash(first, second);
        }

        public A getFirst() {
            return first;
        }

        public B getSecond() {
            return second;
        }
    }
}