#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100002;
const int MAXM = 200002;
const int INF = 1e9;
int n, m, res[MAXM], c[MAXN], f[MAXN];
pair<int, int> d[MAXN];
vector<pair<int, int> > g[MAXN];
void readInput() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i].first;
    f[i] = d[i].first;
    d[i].second = i;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
}
void dfs(int u) {
  for (auto e : g[u]) {
    int v = e.first;
    if (f[u] == f[v] && c[v] == -1) {
      c[v] = c[u] ^ 1;
      res[e.second] = f[u];
      dfs(v);
    }
  }
}
void solve() {
  for (int u = 1; u <= n; ++u) {
    int cnt = 0;
    for (auto e : g[u]) {
      int v = e.first;
      cnt += (f[v] > f[u]);
    }
    if (cnt == g[u].size()) {
      cout << -1;
      return;
    }
  }
  sort(d + 1, d + n + 1);
  for (int i = 1; i <= n; ++i) c[i] = -1;
  for (int i = 1; i <= m; ++i) res[i] = INF;
  for (int i = 1; i <= n;) {
    int j = i - 1;
    while (j + 1 <= n && d[j + 1].first == d[i].first) {
      ++j;
      int u = d[j].second;
      for (auto e : g[u]) {
        int v = e.first;
        if (f[v] < f[u]) {
          c[u] = c[v] ^ 1;
          res[e.second] = f[u];
          break;
        }
      }
      if (c[u] != -1) dfs(u);
    }
    for (int t = i; t <= j; ++t) {
      int u = d[t].second;
      if (c[u] == -1) {
        c[u] = 0;
        dfs(u);
      }
    }
    i = j + 1;
  }
  for (int i = 1; i <= n; ++i) {
    int u = d[i].second;
    bool ok = false;
    for (auto e : g[u]) {
      ok = ok || (res[e.second] == d[i].first);
      assert(res[e.second] >= d[i].first);
    }
    if (!ok) {
      cout << -1;
      assert(0);
      return;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << ((c[i] == 0) ? 'B' : 'W');
  }
  cout << '\n';
  for (int i = 1; i <= m; ++i) {
    cout << res[i] << '\n';
  }
}
int main() {
  readInput();
  solve();
}
