#include <bits/stdc++.h>
using namespace std;
const long long INFLL = (1ll << 60);
const int INF = (int)(1e9);
bool used[225816], visited[100100], color[100100];
int a[225816], b[225816], ans[225816], d[100100];
vector<pair<int, int> > g[100100];
void dfs(int u) {
  int i, v, e;
  visited[u] = true;
  for (i = (g[u].size() - 1); i >= 0; --i) {
    v = g[u][i].first;
    e = g[u][i].second;
    if (!used[e]) {
      continue;
    }
    if (visited[v]) {
      continue;
    }
    color[v] = (!color[u]);
    dfs(v);
  }
}
int main(void) {
  int n, m, u, v, i, j, e;
  bool flag;
  pair<int, int> tmp;
  fill(ans, ans + 225816, INF);
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> d[i];
  }
  for (j = 0; j < m; ++j) {
    cin >> a[j] >> b[j];
    --a[j];
    --b[j];
    if (a[j] > b[j]) {
      swap(a[j], b[j]);
    }
    g[a[j]].push_back(pair<int, int>(b[j], j));
    g[b[j]].push_back(pair<int, int>(a[j], j));
  }
  for (u = 0; u < n; ++u) {
    tmp = pair<int, int>(INF, INF);
    for (i = (g[u].size() - 1); i >= 0; --i) {
      v = g[u][i].first;
      e = g[u][i].second;
      tmp = min(tmp, pair<int, int>(d[v], v));
    }
    if (tmp.first > d[u]) {
      cout << "-1" << endl;
      return 0;
    }
    for (i = (g[u].size() - 1); i >= 0; --i) {
      v = g[u][i].first;
      e = g[u][i].second;
      if (tmp.second == v) {
        ans[e] = d[u];
        used[e] = true;
        break;
      }
    }
  }
  for (i = 0; i < n; ++i) {
    if (visited[i]) {
      dfs(i);
    }
    cout << ((color[i]) ? "B" : "W");
  }
  cout << endl;
  for (j = 0; j < m; ++j) {
    cout << ans[j] << endl;
  }
  return 0;
}
