#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,M; cin>>N>>M;
    vector<P> D;
    rep(i,N){
        ll d; cin>>d;
        D.emplace_back(d,i);
    }
    vector<P> A[N];
    vector<ll> nodeiro(N,0);
    vector<ll> wans(M,0);
    bool nodeused[N]={};
    bool henused[M]={};
    rep(i,M){
        ll u,v; cin>>u>>v; --u,--v;
        A[u].emplace_back(v,i);
        A[v].emplace_back(u,i);
    }

    SORT(D);

    rep(i,N){
        ll ct=1;
        while(i+ct!=N and D[i].first==D[i+ct].first){
            ++ct;
        }
        rep(j,ct){
            nodeused[D[i+j].second]=true;
        }
        if(ct==1){
            bool ok=false;
            for(auto pe: A[D[i].second]){
                ll tugi=pe.first;
                if(nodeused[tugi]) ok=true;
            }
            if(!ok) dame;
        }
        rep(j,ct){
            ll now=D[i+j].second;
            for(auto pe: A[D[i+j].second]){
                ll tugi=pe.first;
                if(nodeused[tugi]){
                    wans[pe.second]=D[i].first;
                    if(nodeiro[tugi]==0) nodeiro[now]=1;
                    if(nodeiro[tugi]==1) nodeiro[now]=2;
                    if(nodeiro[tugi]==2) nodeiro[now]=1;

                }
            }
        }
        i+=ct;

    }

    rep(i,N){
        cout<< ( nodeiro[i]==1 ? 'W' : 'D' );
    }
    cout<<"\n";
    rep(i,M){
        cout<< wans[i] <<"\n";
    }

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------
