///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int d[M];
int c[M];
map<pi,int>id;
vector<pi>edg;
int w[M];
bool cmp(pi a,pi b)
{
    int u1=a.fi;
    int v1=a.si;
    int u2=b.fi;
    int v2=b.si;
    if(d[u1]!=d[u2])return d[u1]<d[u2];
    if(d[v1]!=d[v2])return d[v1]<d[v2];
    return a<b;
}
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    f(i,0,n-1)cin>>d[i];
    memset(c,-1,sizeof c);
    f(i,0,m-1)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        if(d[u]<d[v])swap(u,v);
        id[mp(u,v)]=i;
        edg.pb(mp(u,v));
    }
    sort(edg.begin(),edg.end(),cmp);
    f(i,0,m-1)
    {
        int u=edg[i].fi;
        int v=edg[i].si;
        int du=d[u];
        int dv=d[v];
        if(c[u]==-1 && c[v]==-1)
        {
            if(du!=dv)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            c[u]=1;
            c[v]=0;
            w[id[mp(u,v)]]=du;
        }
        else if(c[u]==-1)
        {
            c[u]=c[v]^1;
            w[id[mp(u,v)]]=du;
        }
        else if(c[v]==-1)
        {
            if(du!=dv)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            w[id[mp(u,v)]]=dv;
            c[v]=c[u]^1;
        }
        else
        {
            w[id[mp(u,v)]]=inf;
        }
    }
    f(i,0,n-1)
    {
        if(c[i]==1)cout<<"W";
        else cout<<"B";
    }
    cout<<"\n";
    f(i,0,m-1)
    {
      cout<<w[i]<<"\n";
    }
    return 0;

}



































