#include <cstdio>
#include <bitset>
#include <vector>
using namespace std;

#define MAX 2000

int n, m;
bitset<MAX> col;
bitset<MAX> a[MAX];
vector<int> res;

int score (int x) {
  // assert(col[x] == 1);
  // number of white neighbours - number of black neighbours
  bitset<MAX> w = a[x] & ~col, b = a[x] & col;
  return w.count() - b.count();
}

void click (int x) {
  // assert col[x] == -1
  col[x] = 0;
  col ^= a[x]; // flip colors of the neighbours
  for (int y=0; y<n; ++y)
    if (a[x][y]) a[y] ^= a[x];
  for (int y=0; y<n; ++y)
    if (a[x][y]) a[x][y] = a[y][x] = a[y][y] = 0;
}


void solve() {
  while (1) {
    int s = -9999, x = -1, tmp;
    for (int y=0; y<n; ++y) if (col[y]) {
      if (s < (tmp = score(y))) {
        s = tmp; x = y;
      }
    }
    if (x == -1) break;
    res.push_back(x);
    click (x);
  }
}

int main() {
  int T, x, y;
  char s[MAX];

  scanf ("%d", &T);
  for (int t = 0; t < T; ++t) {
    col.reset();
    for (int i =0; i<MAX; ++i) a[x].reset();

    scanf ("%d %d\n", &n, &m);
    scanf ("%s", s);
    for (int i=0; i<n; ++i) {
      col[i] = (s[i] == 'B');
    }
    for (int i=0; i<m; ++i) {
      scanf ("%d %d", &x, &y);
      a[x][y] = a[y][x] = 1;
    }
    solve ();
    printf ("%d\n", res.size());
    for (int i=0; i < res.size(); ++i) {
      printf ("%d ", res[i]);
    }
    printf ("\n\n");
    res.clear();
  }
  return 0;
}

