#include <bits/stdc++.h>
using namespace std;
mt19937 rnd;
struct Edge {
  int u, v, w;
};
const int N = 1e5 + 10, inf = 1e9;
vector<Edge> edges;
vector<pair<int, int> > g[N];
vector<int> e[N];
int d[N], color[N];
pair<int, int> go[N];
bool root[N], good[N];
vector<pair<int, int> > notdone;
void dfs(int v, int col) {
  for (pair<int, int> e : g[v]) {
    int to = e.first, id = e.second;
    if (color[to]) continue;
    color[to] = col;
    if (color[v] != color[to]) {
      edges[id].w = d[to];
    } else {
      edges[id].w = d[to] - d[v];
    }
    dfs(to, col);
  }
}
void dfs2(int v, int col) {
  color[v] = col;
  for (int to : e[v]) {
    if (color[to]) continue;
    dfs2(to, 3 - col);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    root[i] = 1;
  }
  for (int i = 0; i <= m - 1; i++) {
    int u, v;
    cin >> u >> v;
    if (d[u] > d[v]) swap(u, v);
    edges.push_back({u, v, inf});
  }
  for (int i = 0; i <= m - 1; i++) {
    int u = edges[i].u, v = edges[i].v;
    if (d[u] < d[v]) {
      g[u].push_back({v, i});
      root[v] = 0;
      good[v] = 1;
    } else {
      good[u] = good[v] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!good[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 0; i <= m - 1; i++) {
    int u = edges[i].u, v = edges[i].v;
    if (d[u] == d[v] && root[u] && root[v]) {
      e[u].push_back(v), e[v].push_back(u);
      edges[i].w = d[u];
    }
  }
  for (int i = 0; i <= m - 1; i++) {
    int u = edges[i].u, v = edges[i].v;
    if (d[u] == d[v]) {
      if (root[u] && root[v]) {
        continue;
      } else if (root[u]) {
        go[u] = {v, i};
      } else if (root[v]) {
        go[v] = {u, i};
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (root[i] && !color[i] && !e[i].empty()) {
      dfs2(i, 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (root[i] && color[i]) {
      dfs(i, 3 - color[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (root[i] && e[i].empty()) {
      notdone.push_back({d[i], i});
    }
  }
  sort(notdone.begin(), notdone.end());
  for (int i = 0; i < notdone.size(); i++) {
    int v = notdone[i].second;
    int to = go[v].first, id = go[v].second;
    edges[id].w = d[v];
    color[v] = 3 - color[to];
    dfs(i, 3 - color[v]);
  }
  for (int i = 1; i <= n; i++) {
    if (color[i] == 1)
      cout << "B";
    else
      cout << "W";
  }
  cout << "\n";
  for (int i = 0; i <= m - 1; i++) {
    cout << edges[i].w << "\n";
  }
  return 0;
}
