#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long>>> v(111111);
long long d[111111];
long long c[222222];
long long color[111111];
long long used[111111];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long(i) = (0); (i) < (n); ++i) cin >> d[i];
  for (long long(i) = (0); (i) < (m); ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].emplace_back(b, i);
    v[b].emplace_back(a, i);
  }
  queue<long long> q;
  for (long long(i) = (0); (i) < (n); ++i) {
    for (long long(j) = (0); (j) < (v[i].size()); ++j) {
      int aite = v[i][j].first;
      int edge_id = v[i][j].second;
      if (d[i] == d[aite]) {
        if (color[i] != 0 && color[aite] != 0) continue;
        if (color[i] == 0) {
          if (color[aite] != 0)
            color[i] = -color[aite];
          else
            color[i] = 1;
        }
        if (color[aite] == 0) color[aite] = -color[i];
        q.push(i);
        q.push(aite);
        c[edge_id] = d[i];
      }
    }
  }
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    if (used[id]) continue;
    used[id] = true;
    for (long long(i) = (0); (i) < (v[id].size()); ++i) {
      int aite = v[id][i].first;
      int edge_id = v[id][i].second;
      if (used[aite]) continue;
      if (d[aite] <= d[i]) continue;
      if (color[aite] != 0) continue;
      color[aite] = color[i];
      c[edge_id] = d[aite] - d[i];
      q.push(aite);
    }
  }
  for (long long(i) = (0); (i) < (n); ++i) {
    if (!used[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long(i) = (0); (i) < (n); ++i) cout << (color[i] == 1 ? 'B' : 'W');
  cout << endl;
  for (long long(i) = (0); (i) < (m); ++i)
    cout << (c[i] == 0 ? 1000000000 : c[i]) << endl;
  return 0;
}
