#include <bits/stdc++.h>
using namespace std;
int n, t;
vector<int> dv[600000];
string s;
int res[600000];
const long double PI = acos(-1);
void fft(vector<complex<double> > &a, bool invert) {
  int n = (int)a.size();
  for (int i = 1, j = 0; i < n; ++i) {
    int bit = (n >> 1);
    for (; j >= bit; bit >>= 1) j -= bit;
    j += bit;
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    double ang = 2 * PI / len * (invert ? -1 : 1);
    complex<double> wlen(cos(ang), sin(ang));
    for (int i = 0; i < n; i += len) {
      complex<double> w(1);
      for (int j = 0; j < len / 2; ++j) {
        complex<double> u = a[i + j], v = a[i + j + len / 2] * w;
        a[i + j] = u + v;
        a[i + j + len / 2] = u - v;
        w *= wlen;
      }
    }
  }
  if (invert)
    for (int i = 0; i < n; ++i) a[i] /= n;
}
int get_int() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
string getstring() {
  char c = getchar();
  string s;
  while (c == 'V' || c == 'K' || c == '?') {
    s += c;
    c = getchar();
  }
  return s;
}
int main() {
  t = get_int();
  for (int j = 1; j <= 500000; j++) {
    for (int i = j; i <= 500000; i += j) dv[i].push_back(j);
  }
  for (; t >= 1; t--) {
    n = get_int();
    s = getstring();
    vector<int> a;
    vector<int> b;
    a.resize(n + n);
    b.resize(n + n);
    for (int i = 0; i < n + n; i++) {
      a[i] = b[i] = 0;
    }
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'V') {
        a[n - 1 - i] = 1;
        b[i + n] = 0;
      } else if (s[i] == 'K') {
        a[n - 1 - i] = 0;
        b[i + n] = 1;
      }
    }
    int mx = 0;
    for (int i = 1; i <= 23; i++)
      if ((1 << i) >= n * 4) {
        mx = (1 << i);
        break;
      }
    a.resize(mx);
    b.resize(mx);
    for (int i = n + n; i < mx; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    vector<complex<double> > fa, fb;
    fa.resize(mx);
    fb.resize(mx);
    for (int i = 0; i < mx; i++) {
      fa[i] = a[i];
      fb[i] = b[i];
    }
    fft(fa, 0), fft(fb, 0);
    for (int i = 0; i < fa.size(); i++) fa[i] *= fb[i];
    fft(fa, 1);
    for (int i = 1; i <= n; i++) res[i] = 0;
    for (int i = n; i < n + n + n; i++)
      res[abs(i - (n + n - 1))] += (int)(fa[i].real() + 0.5);
    vector<int> ans;
    for (int i = n; i >= 1; i--) {
      if (res[i] == 0)
        ans.push_back(i);
      else {
        for (int j = 0; j < dv[i].size(); j++) res[dv[i][j]] = 1;
      }
    }
    cout << ans.size() << "\n";
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << "\n";
  }
  return 0;
}
