#include <bits/stdc++.h>
using namespace std;
vector<vector<array<int, 2>>> v(100010);
char c[100010];
bool ok[100010];
long long ans[200010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  long long n, m;
  cin >> n >> m;
  long long d[n];
  array<long long, 2> a[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    a[i] = {d[i], i};
  }
  sort(a, a + n);
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    b--, c--;
    v[b].push_back({c, i});
    v[c].push_back({b, i});
  }
  for (int i = 0; i < n; i++) {
    if (!ok[i]) {
      bool pos = false;
      for (auto j : v[i]) {
        if (!ok[j[0]] && d[j[1]] == d[i]) {
          pos = 1;
          break;
        }
      }
      if (!pos) {
        cout << -1 << endl;
        return 0;
      }
      ok[i] = 1;
      c[i] = 'W';
    }
    ok[i] = 1;
    for (auto j : v[i]) {
      ok[c[j[0]]] = 1;
      if (!c[j[0]]) c[j[0]] = 'B';
      if (!ans[j[1]]) ans[j[1]] = max(d[j[0]], d[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << c[i];
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    cout << ans[i] << "\n";
  }
}
