#include <bits/stdc++.h>
namespace IO {
static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
inline char myGetchar() {
  static char buf[IN_BUF], *ps = buf, *pt = buf;
  if (ps == pt) {
    ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
  }
  return ps == pt ? EOF : *ps++;
}
template <typename T>
inline bool read(T &x) {
  bool op = 0;
  char ch = IO::myGetchar();
  x = 0;
  for (; !isdigit(ch) && ch != EOF; ch = IO::myGetchar()) {
    op ^= (ch == '-');
  }
  if (ch == EOF) {
    return false;
  }
  for (; isdigit(ch); ch = IO::myGetchar()) {
    x = x * 10 + (ch ^ '0');
  }
  if (op) {
    x = -x;
  }
  return true;
}
inline int readStr(char *s) {
  int n = 0;
  char ch = IO::myGetchar();
  for (; isspace(ch) && ch != EOF; ch = IO::myGetchar())
    ;
  for (; !isspace(ch) && ch != EOF; ch = IO::myGetchar()) {
    s[n++] = ch;
  }
  s[n] = '\0';
  return n;
}
inline void myPutchar(char x) {
  static char pbuf[OUT_BUF], *pp = pbuf;
  struct _flusher {
    ~_flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); }
  };
  static _flusher outputFlusher;
  if (pp == pbuf + OUT_BUF) {
    fwrite(pbuf, 1, OUT_BUF, stdout);
    pp = pbuf;
  }
  *pp++ = x;
}
template <typename T>
inline void print_(T x) {
  if (x == 0) {
    IO::myPutchar('0');
    return;
  }
  static int num[40];
  if (x < 0) {
    IO::myPutchar('-');
    x = -x;
  }
  for (*num = 0; x; x /= 10) {
    num[++*num] = x % 10;
  }
  while (*num) {
    IO::myPutchar(num[*num] ^ '0');
    --*num;
  }
}
template <typename T>
inline void print(T x, char ch = '\n') {
  print_(x);
  IO::myPutchar(ch);
}
inline void printStr_(const char *s, int n = -1) {
  if (n == -1) {
    n = strlen(s);
  }
  for (int i = 0; i < n; ++i) {
    IO::myPutchar(s[i]);
  }
}
inline void printStr(const char *s, int n = -1, char ch = '\n') {
  printStr_(s, n);
  IO::myPutchar(ch);
}
}  // namespace IO
using namespace IO;
const int N = 100005, M = 200005, INF = 1000000000;
int n, m, D[N], col[N], flag[N];
std::vector<std::pair<int, int>> E[N];
int ans[M];
void dfs(int u) {
  for (auto p : E[u]) {
    int v = p.first, id = p.second;
    if (col[v] == -1) {
      if (D[u] == D[v]) {
        col[v] = col[u] ^ 1;
        ans[id] = D[u];
        dfs(v);
      }
    } else if (ans[id] == -1) {
      ans[id] = INF;
    }
  }
  for (auto p : E[u]) {
    int v = p.first, id = p.second;
    if (col[v] == -1) {
      if (D[u] < D[v]) {
        col[v] = col[u];
        ans[id] = D[v] - D[u];
        dfs(v);
      }
    }
  }
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    read(D[i]);
    col[i] = -1;
    flag[i] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    read(u), read(v), ans[i] = -1;
    E[u].push_back({v, i}), E[v].push_back({u, i});
    if (D[v] <= D[u]) {
      flag[u] = 1;
    }
    if (D[u] <= D[v]) {
      flag[v] = 1;
    }
  }
  if (*std::min_element(flag + 1, flag + 1 + n) == 0) {
    print(-1);
    return 0;
  }
  int rt = std::min_element(D + 1, D + 1 + n) - D;
  col[rt] = 0, dfs(rt);
  for (int i = 1; i <= n; ++i) {
    if (col[i] == 0) {
      IO::myPutchar('W');
    } else {
      IO::myPutchar('B');
    }
  }
  IO::myPutchar('\n');
  for (int i = 1; i <= m; ++i) {
    print(ans[i]);
  }
}
