#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, a, b;
vector<int> d, ans;
vector<vector<pair<int, int>>> v;
vector<bool> vs, c;
void rec(int i, bool f = false) {
  if (vs[i]) return;
  vs[i] = true;
  c[i] = f;
  for (auto& j : v[i])
    if (ans[j.second] != -1) {
      rec(j.first, !f);
    }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  istream& in(cin);
  ostream& out(cout);
  in >> n >> m;
  d.resize(n);
  v.resize(n);
  for (auto& i : d) in >> i;
  for (int i = 0; i < (m); ++i) {
    in >> a >> b;
    --a, --b;
    v[a].emplace_back(b, i);
    v[b].emplace_back(a, i);
  }
  for (int i = 0; i < (n); ++i) {
    sort(v[i].begin(), v[i].end(), [&](pair<int, int> x, pair<int, int> y) {
      return d[x.first] < d[y.first];
    });
    if (d[i] < d[v[i][0].first]) return cout << -1 << endl, 0;
  }
  c.resize(n);
  ans.resize(m, -1);
  vector<int> vis(n, -1);
  for (int i = 0; i < (n); ++i) {
    if (vis[i] == d[i]) continue;
    int j, e;
    tie(j, e) = v[i][0];
    vis[j] = ans[i] = d[i];
  }
  vs.resize(n);
  for (int i = 0; i < (n); ++i) rec(i);
  for (int i = 0; i < (n); ++i) cout << (c[i] ? "B" : "W");
  cout << endl;
  for (int i = 0; i < (m); ++i)
    cout << (ans[i] == -1 ? 1000000000 : ans[i]) << endl;
}
