#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<long long int> &vec_s, int vec_n = -1,
                char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
map<int, int> m1;
vector<int> v1[110000];
vector<pair<int, int> > path[110000];
int ps[220000];
int dd[110000];
int col[110000];
int main() {
  int n, m;
  int i, j, k;
  int a, b, c;
  cin >> n >> m;
  for (i = 0, j = 0; i < n; i++) {
    cin >> a;
    if (m1.find(a) == m1.end()) m1[a] = j++;
    v1[m1[a]].push_back(i);
    dd[i] = a;
  }
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    path[a].push_back(make_pair(b, i));
    path[b].push_back(make_pair(a, i));
    ps[i] = 1e9;
  }
  memset(col, -1, sizeof(col));
  bool flag = false, fflag = false;
  for (auto itr : m1) {
    a = itr.second;
    for (auto node : v1[a]) {
      flag = false, fflag = false;
      for (auto to : path[node]) {
        if (dd[to.first] == itr.first) {
          if (col[to.first] != -1) {
            col[node] = 1 - col[to.first];
            ps[to.second] = itr.first;
            fflag = true;
            break;
          }
          flag = true;
        }
      }
      if (fflag) continue;
      if (flag) {
        col[node] = 0;
        continue;
      }
      for (auto to : path[node]) {
        if (dd[to.first] < itr.first) {
          col[node] = col[to.first];
          ps[to.second] = itr.first - dd[to.first];
          flag = true;
          break;
        }
      }
      if (!flag) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (col[i] == 1)
      cout << 'W';
    else
      cout << 'B';
  }
  cout << endl;
  for (i = 0; i < m; i++) {
    cout << ps[i] << endl;
  }
}
