using System;
using System.Collections.Generic;

public class Program
{
    private int N, M;
    private int[] D;
    private List<E>[] Edge;

    private HashSet<E>[] nokosu;
    private char[] S;
    private int[] C;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        D = sc.IntArray();
        Edge = new List<E>[N];
        for (int i = 0; i < N; i++)
        {
            Edge[i] = new List<E>();
        }

        for (int i = 0; i < M; i++)
        {
            int u = sc.NextInt() - 1;
            int v = sc.NextInt() - 1;
            Edge[u].Add(new E(u, v, i));
            Edge[v].Add(new E(v, u, i));
        }

        /*
         * 
         * 
         * D[u] uと繋がってる任意の頂点v
         * D[u] < D[v] なら-1
         *
         * uから一番近い頂点 パス u,u_2...u_k
         * 
         * k == 2
         * 一つのvが u[k]になる
         * D[v] <= D[u]
         * 
         * else
         * 一つのvが u_2になる
         * u ~ u_k > u_2 ~ u_k
         *
         * uに繋がってる D[v]が最小のvの辺を残す
         *
         * u,vは別色 　辺の長さは D[u]
         *
         * 消した辺は適当に大きい数を入れる
         * 
         */
        S = new char[N];
        C = new int[M];

        for (int i = 0; i < M; i++)
        {
            C[i] = 1000000000;
        }

        nokosu = new HashSet<E>[N];
        for (int i = 0; i < N; i++)
        {
            nokosu[i] = new HashSet<E>();
        }

        for (int i = 0; i < N; i++)
        {
            int min = int.MaxValue;
            E edge = new E(-1, -1, -1);
            foreach (E e in Edge[i])
            {
                if (D[e.V] < min)
                {
                    edge = e;
                    min = D[e.V];
                }
            }

            if (D[i] < min)
            {
                Console.WriteLine("-1");
                return;
            }

            C[edge.Index] = D[i];

            nokosu[edge.U].Add(edge);
            nokosu[edge.V].Add(new E(edge.V, edge.U, edge.Index));
        }

        for (int i = 0; i < N; i++)
        {
            if (S[i] == default(char))
            {
                Search(i, -1, 'W');
            }
        }

        Console.WriteLine(new string(S));
        Console.WriteLine(string.Join("\n", C));
    }

    private void Search(int i, int parent, char col)
    {
        S[i] = col;
        foreach (E e in nokosu[i])
        {
            if (e.V == parent) continue;
            Search(e.V, i, col == 'B' ? 'W' : 'B');
        }
    }


    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

struct E
{
    public int U, V;
    public int Index;

    public E(int u, int v, int i)
    {
        U = u;
        V = v;
        Index = i;
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 78328