#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
const int N = 2e5 + 5;
int n, m;
int d[N];
vector<int> g[N];
pair<int, int> edge[N]{};
vector<int> h[N];
int res[N];
int color[N];
inline int get_to(int id, int v) {
  return edge[id].first == v ? edge[id].second : edge[id].first;
}
int used[N];
void dfs(int v) {
  used[v] = 1;
  for (int id : g[v]) {
    int to = get_to(id, v);
    if (!used[to]) {
      h[v].push_back(id);
      dfs(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    color[i] = -1;
  }
  for (int u, v, i = 0; i < m; i++) {
    cin >> u >> v;
    if (d[u] > d[v]) swap(u, v);
    edge[i] = {u, v};
    g[u].push_back(i);
    if (d[u] == d[v]) g[v].push_back(i);
    res[i] = inf;
  }
  vector<int> roots;
  for (int v = 1; v <= n; v++) {
    if (color[v] != -1) continue;
    int any = 0;
    for (int id : g[v]) {
      int to = get_to(id, v);
      if (color[to] != -1) continue;
      if (d[v] == d[to]) {
        any = 1;
        color[v] = 0;
        color[to] = 1;
        break;
      }
    }
    if (any) roots.push_back(v);
  }
  for (int root : roots) {
    d[root] = 0;
  }
  for (int root : roots) {
    dfs(root);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int v = 1; v <= n; v++) {
    for (int id : h[v]) {
      int to = get_to(id, v);
      res[id] = d[to] - d[v];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (color[i] == -1) color[i] = 1;
    if (color[i])
      cout << "B";
    else
      cout << "W";
  }
  cout << "\n";
  for (int i = 0; i < m; i++) {
    cout << res[i] << "\n";
  }
  return 0;
}
