#include <bits/stdc++.h>
using namespace std;
int n, m, D[100005], id[100005], d[100005];
int col[100005];
using pii = pair<int, int>;
vector<pii> v[100005];
bool vis[100005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &D[i]), id[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d %d", &x, &y);
    v[x].emplace_back(y, i);
    v[y].emplace_back(x, i);
  }
  sort(id + 1, id + n + 1, [](int x, int y) { return D[x] < D[y]; });
  memset(col, -1, sizeof col);
  for (int i = 1; i <= n; i++) {
    int u = id[i];
    if (vis[u]) continue;
    bool flag = 0;
    for (auto x : v[u])
      if (vis[x.first]) {
        d[x.second] = D[u];
        col[u] = col[x.first] ^ 1;
        flag = 1;
        vis[u] = 1;
        break;
      }
    if (flag) continue;
    for (auto x : v[u])
      if (D[x.first] == D[u]) {
        d[x.second] = D[u];
        vis[u] = vis[x.first] = 1;
        col[u] = 1, col[x.first] = 0;
        flag = 1;
        break;
      }
    if (!flag) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) printf("%c", "BW"[col[i]]);
  puts("");
  for (int i = 1; i <= m; i++) {
    if (d[i] == 0) d[i] = 1e9;
    printf("%d\n", d[i]);
  }
  return 0;
}
