#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n, m, d[N];
vector<int> g[N];
pair<int, int> p[N];
map<pair<int, int>, int> id;
set<int> st;
int col[N], ans[N];
void dfs(int u) {
  int cnt = 0;
  for (auto v : g[u]) {
    if (st.count(v)) {
      if (col[v] == 0) {
        col[v] = 3 - col[u];
        ans[id[make_pair(u, v)]] = d[u];
        cnt++;
        dfs(v);
      } else if (col[v] + col[u] == 3) {
        cnt++;
      }
    }
    if (col[v] == 3 - col[u]) {
      ans[id[make_pair(u, v)]] = d[u];
      cnt++;
    }
  }
  if (cnt == 0) {
    printf("-1\n");
    exit(0);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]), p[i] = make_pair(d[i], i);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    id[make_pair(x, y)] = id[make_pair(y, x)] = i;
  }
  sort(p + 1, p + 1 + n);
  for (int i = 1, j = 1; i <= n; i = j) {
    vector<int> tmp;
    st.clear();
    while (j <= n && p[j].first == p[i].first) {
      tmp.push_back(p[j].second);
      st.insert(p[j].second);
      j++;
    }
    for (auto x : tmp) {
      if (col[x] == 0) {
        for (auto v : g[x]) {
          if (col[v]) {
            col[x] = 3 - col[v];
          }
        }
        if (!col[x]) col[x] = 1;
        dfs(x);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%c", col[i] == 1 ? 'W' : 'B');
  }
  printf("\n");
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i] ? ans[i] : (int)1e9);
  }
}
