#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
struct Forest_Uni {
  vector<UL> v;
  void init(UL n) {
    v.clear();
    for (UL i = 0; i < (n); i++) v.push_back(i);
  }
  UL root(UL p) {
    if (v[p] == p) return p;
    return v[p] = root(v[p]);
  }
  void unite(UL a, UL b) {
    UL A = root(a);
    UL B = root(b);
    if (A != B) {
      v[A] = B;
    }
  }
};
struct Problem {
  void Solve() {
    UL N, M;
    cin >> N >> M;
    vector<UL> D(N);
    vector<vector<pair<UL, UL>>> E(N);
    vector<UL> Col(N);
    vector<UL> ans(M);
    for (UL i = 0; i < (M); i++) ans[i] = 1000000000;
    for (UL i = 0; i < (N); i++) cin >> D[i];
    for (UL i = 0; i < (M); i++) {
      UL u, v;
      cin >> u >> v;
      u--;
      v--;
      E[u].push_back({v, i});
      E[v].push_back({u, i});
    }
    vector<vector<pair<UL, UL>>> Dep(N);
    Forest_Uni F;
    F.init(N);
    for (UL i = 0; i < (N); i++) {
      bool ok = false;
      for (auto &e : E[i]) {
        if (D[i] > D[e.first]) {
          Dep[e.first].push_back({i, e.second});
          ok = true;
          break;
        }
      }
      if (!ok) {
        for (auto &e : E[i]) {
          if (D[i] == D[e.first]) {
            ok = true;
            if (F.root(i) == F.root(e.first)) continue;
            Dep[e.first].push_back({i, e.second});
            F.unite(i, e.first);
            break;
          }
        }
      }
      if (!ok) {
        cout << -1 << endl;
        return;
      }
    }
    queue<pair<UL, UL>> q;
    vector<pair<UL, UL>> li(N);
    for (UL i = 0; i < (N); i++) li[i] = {D[i], i};
    sort(li.begin(), li.end());
    for (UL i = 0; i < (N); i++) {
      UL p = li[i].second;
      if (Col[p]) continue;
      q.push({p, 1});
      while (q.size()) {
        auto pp = q.front();
        q.pop();
        Col[pp.first] = pp.second;
        for (auto &ppp : Dep[pp.first]) {
          if (D[pp.first] == D[ppp.first]) {
            q.push({ppp.first, 3 - pp.second});
            ans[ppp.second] = D[pp.first];
          } else {
            q.push({ppp.first, pp.second});
            ans[ppp.second] = D[ppp.first] - D[pp.first];
          }
        }
      }
    }
    for (UL i = 0; i < (N); i++) {
      if (Col[i] == 1)
        cout << "W";
      else
        cout << "B";
    }
    cout << endl;
    for (UL i = 0; i < (N); i++) {
      cout << ans[i] << endl;
    }
  }
  Problem();
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem::Problem() { cout << fixed << setprecision(10); }
