#include <bits/stdc++.h>
using namespace std;
inline void Input_Output() {}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
int a[N];
vector<int> g[N];
int w[N];
int c[N];
int u[N];
int d[N];
pair<int, int> e[N];
queue<int> q;
void dfs(int v) {
  for (auto to : g[v]) {
    if (c[to] == -1) {
      c[to] = (c[v] ^ 1);
      dfs(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i] = -1;
  }
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    if (a[l] == a[r]) {
      w[i] = a[l];
      g[l].push_back(r);
      g[r].push_back(l);
      u[l] = u[r] = 1;
    } else {
      if (a[l] < a[r])
        u[r] = 1;
      else
        u[l] = 1;
    }
    e[i] = make_pair(l, r);
  }
  for (int i = 1; i <= n; i++)
    if (!u[i]) {
      cout << "-1\n";
      exit(0);
    }
  exit(0);
  for (int i = 1; i <= n; i++)
    if (c[i] == -1) {
      c[i] = 0;
      dfs(i);
    }
  for (int i = 1; i <= n; i++) {
    assert(c[i] != -1);
  }
  for (int i = 1; i <= m; i++) {
    int l, r;
    tie(l, r) = e[i];
    if (a[l] != a[r]) {
      if (c[l] == c[r])
        w[i] = abs(a[l] - a[r]);
      else
        w[i] = 1000000000;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] == 1)
      cout << 'B';
    else
      cout << 'W';
  }
  cout << '\n';
  for (int i = 1; i <= m; i++) {
    cout << w[i] << '\n';
  }
  return 0;
}
