#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) d[i] = in();
  vector<vector<int> > e(n), id(n);
  vector<vector<int> > esame(n), idsame(n);
  ;
  for (int i = 0; i < m; ++i) {
    int u = in() - 1, v = in() - 1;
    e[u].push_back(v);
    id[u].push_back(i);
    e[v].push_back(u);
    id[v].push_back(i);
    if (d[u] == d[v]) {
      esame[u].push_back(v);
      idsame[u].push_back(i);
      esame[v].push_back(u);
      idsame[v].push_back(i);
    }
  }
  vector<int> col(n, -1), ans(m, INF);
  for (int i = 0; i < n; ++i) {
    if (esame[i].empty() || col[i] != -1) continue;
    queue<int> que;
    col[i] = 0;
    que.push(i);
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      for (int j = 0; j < esame[now].size(); ++j) {
        int next = esame[now][j];
        int id = idsame[now][j];
        if (col[next] == -1) {
          col[next] = !col[now];
          que.push(next);
          ans[id] = d[now];
        }
      }
    }
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  vector<int> dist(n, INF + 10);
  for (int i = 0; i < n; ++i) {
    if (col[i] == -1) col[i] = 1;
    if (col[i] == 0) {
      dist[i] = 0;
      que.push(pair<int, int>(0, i));
    }
  }
  while (!que.empty()) {
    pair<int, int> tmp = que.top();
    que.pop();
    int now = tmp.second;
    if (dist[now] < tmp.first) continue;
    for (int j = 0; j < e[now].size(); ++j) {
      int next = e[now][j];
      if (col[next] == 0) continue;
      if (d[next] == dist[next]) continue;
      if (dist[now] < d[next]) {
        dist[next] = d[next];
        ans[id[now][j]] = d[next] - dist[now];
        que.push(pair<int, int>(dist[next], next));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (col[i] == 1 && dist[i] != d[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) cout << "WB"[col[i]];
  cout << endl;
  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
  return 0;
}
