#include <bits/stdc++.h>
using namespace std;
void solve(int n, int m, map<int, vector<int>> &g,
           map<pair<int, int>, int> &edge, vector<pair<long long, int>> &d,
           int start) {
  int cur = start;
  int curid = 0;
  vector<long long> ans(m, 1e9);
  map<int, char> mp;
  map<int, bool> used;
  while (curid < n) {
    mp[cur] = (curid % 2 == 0) ? 'B' : 'W';
    int next = d[curid + 1].first;
    bool flag = false;
    for (auto x : g[cur]) {
      if (used[x]) continue;
      if (d[x].first == next) {
        used[x] = true;
        ans[edge[{cur, x}]] = d[curid + 1].first;
        flag = true;
        cur = x;
        break;
      }
    }
    if (flag == false) {
      return;
    }
    curid++;
  }
  mp[cur] = (curid % 2 == 0) ? 'B' : 'W';
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    cout << mp[i];
  }
  cout << endl;
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    cout << ans[i] << endl;
  }
  exit(0);
}
int main(int argc, char const *argv[]) {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, int>> d(n);
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    cin >> d[i].first;
    d[i].second = i;
  }
  sort(d.begin(), d.end());
  if (d[0].first != d[1].first) {
    cout << -1 << endl;
    return 0;
  }
  map<pair<int, int>, int> edge;
  map<int, vector<int>> g;
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
    edge[{u, v}] = i;
    edge[{v, u}] = i;
  }
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    if (d[i].first == d[0].first) {
      solve(n, m, g, edge, d, i);
    }
  }
  cout << -1 << endl;
  return 0;
}
