#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int LINF = 1LL * INF * INF;
const int MAXN = 2e5 + 10;
const int MAXM = 5e3 + 10;
priority_queue<int> pq;
vector<vector<pair<int, int> > > graph;
queue<int> que;
int A[MAXN];
pair<int, int> edge[MAXN];
int ty[MAXN];
int vv[MAXN];
vector<vector<int> > ver;
vector<int> val;
int main() {
  int n, m, k, a, b, x, y, q;
  int sum = 0;
  int cnt = 0;
  int mx = 0;
  int mn = INF;
  int cur = 0, idx = -1;
  int tc;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  graph = vector<vector<pair<int, int> > >(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    val.push_back(A[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> edge[i].first >> edge[i].second;
    graph[edge[i].first].push_back(pair<int, int>(edge[i].second, i));
    graph[edge[i].second].push_back(pair<int, int>(edge[i].first, i));
  }
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  int sz = val.size();
  ver = vector<vector<int> >(sz);
  for (int i = 1; i <= n; i++) {
    idx = lower_bound(val.begin(), val.end(), A[i]) - val.begin();
    ver[idx].push_back(i);
  }
  fill(ty, ty + n + 1, -1);
  int there;
  int ans;
  int anss;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < ver[i].size(); j++) {
      cur = ver[i][j];
      cnt = 0;
      ans = -1;
      anss = -1;
      for (int t = 0; t < graph[cur].size(); t++) {
        there = graph[cur][t].first;
        if (A[there] <= A[cur]) {
          ++cnt;
          if (ty[there] != -1) {
            if (A[there] == A[cur])
              ans = there;
            else
              anss = there;
          }
        }
      }
      if (!cnt) {
        cout << "-1\n";
        return 0;
      }
      if (ans != -1)
        ty[cur] = (1 ^ ty[ans]);
      else if (anss != -1)
        ty[cur] = (1 ^ ty[anss]);
      else
        ty[cur] = 0;
      for (int t = 0; t < graph[cur].size(); t++) {
        there = graph[cur][t].first;
        if (A[there] <= A[cur]) {
          vv[graph[cur][t].second] = A[cur];
        }
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (ty[i])
      cout << "B";
    else
      cout << "W";
  cout << "\n";
  for (int i = 1; i <= m; i++) cout << vv[i] << "\n";
  return 0;
}
