#include <bits/stdc++.h>
using namespace std;
int n, m;
bool used[100010];
int d[100010];
const int INF = 1e9;
vector<pair<int, int> > g[100010];
int a[200020], b[200020];
int c[200020];
string s;
pair<int, int> p[100010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back({b[i], i});
    g[b[i]].push_back({a[i], i});
  }
  for (int i = 0; i < n; i++) s += 'B';
  for (int i = 0; i < n; i++) {
    p[i] = pair<int, int>(d[i], i);
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++) {
    int x = p[i].second;
    int cnt = 0, cnt1 = 0;
    for (auto q : g[x]) {
      int y = q.first, k = q.second;
      if (d[y] > d[x]) continue;
      if (cnt) {
        c[k] = INF;
        continue;
      }
      if (d[y] < d[x]) {
        c[k] = d[x] - d[y];
        cnt++;
      } else if (used[y]) {
        c[k] = d[x];
        if (s[y] == 'B')
          s[x] = 'W';
        else
          s[x] = 'B';
        cnt++;
      }
      cnt1++;
    }
    if (cnt1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    used[x] = 1;
  }
  cout << s << endl;
  for (int i = 0; i < m; i++) {
    cout << c[i] << endl;
  }
  return 0;
}
