#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}else{
		ll ans = 0;
		for(int take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 || left>lo.size()){
				continue;
			}
			if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int MAXN = 46341 + 1;
int spf[46341+1];
int d,x,y;
int gcd(int a , int b){
	if(b==0)return a;
	return gcd(b , a%b);
}
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
ll gcd(ll a , ll b){
	if(b==0)return a;
	return gcd(b , a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

int cost(int x ,int y){
	return ((~x)&y);
}
int solve_(int i , int curr ,vector<  vector<int> >&dp, vector< vector<int> >&v){
	if(i==v.size())return 0;
	int& ret =dp[i][curr];
	if(~ret)return ret;
	ret = INT_MAX;
	for(int j = 0 ; j<v.size();j++){
		ret = min(ret , cost(curr , v[i][j]) + solve_(i+1 , curr|v[i][j] , dp ,v));
	}
	return ret;
}

void solve(){
	ll n ,m , d;
	cin>>n>>d>>m;
	vector<ll> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	int j = 0 , i;
	for(i=n-1;i>=0;i--){
		ll c = d , cost = 0;
		if(a[i]<=m)break;
		while(c-- && j<n){
			cost += a[j];
			j++;
		}
		if(j>=i){
			i++;
			int done = (n-i)*d;
			ll ans = 0;
			for(int j = max(0,done) ; j<n ; j++){
				ans+=a[j];
			}
			cout<<ans;
			return;
		}else{
			if(cost>=a[i]){
				break;
			}
		}
	}
	int done = (n-i-2)*d;
	ll ans = 0;
	for(int j = max(0,done) ; j<n ; j++){
		ans+=a[j];
	}
	cout<<ans;

}
int main(){
	SLAY
	// cin>>_;
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	int n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}else{
		ll ans = 0;
		for(int take = 1;take<=hi.size();take++){
			int left = n - (take-1)*(d+1) - 1;
			if(left<0 || left>lo.size()){
				continue;
			}
			if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);

		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}else{
		ll ans = 0;
		for(int take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>lo.size())ans = max(ans , preHi[take-1] + preLo[lo.size()-1]);
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int MAXN = 46341 + 1;
int spf[46341+1];
int d,x,y;
int gcd(int a , int b){
	if(b==0)return a;
	return gcd(b , a%b);
}
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
ll gcd(ll a , ll b){
	if(b==0)return a;
	return gcd(b , a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

int cost(int x ,int y){
	return ((~x)&y);
}
int solve_(int i , int curr ,vector<  vector<int> >&dp, vector< vector<int> >&v){
	if(i==v.size())return 0;
	int& ret =dp[i][curr];
	if(~ret)return ret;
	ret = INT_MAX;
	for(int j = 0 ; j<v.size();j++){
		ret = min(ret , cost(curr , v[i][j]) + solve_(i+1 , curr|v[i][j] , dp ,v));
	}
	return ret;
}

void solve(){
	ll n ,m , d;
	cin>>n>>d>>m;
	vector<ll> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	int j = 0 , i;
	ll ans = a[n-1];
	for(i=n-2;i>=0;i--){

		if(a[i]<=m){
			for(int k=j;k<=i;k++)ans+=a[k];
			break;
		}

		ll  k= j , c = d, cost =0;
		while(k<i && c && a[k]<=m){
			cost += a[k];
			k++;
			c--;
		}

		if(k<i){
			if(c==0){
				if(cost<a[i]){
					ans+=a[i];
					j=k;
				}else{
					for(int k = j ; k<i ; k++){
						if(a[k]>m)break;
						ans += a[k];
					}
					break;
				}
			}else{
				for(int k = j ; k<i ; k++){
					if(a[k]>m)break;
					ans += a[k];
				}
				break;
			}
		}else if(k==i){
			for(int k = j ; k<i ; k++){
				if(a[k]>m)break;
				ans += a[k];
			}
			break;
		}

	}

	cout<<ans;

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size()+1);
	vector<ll> preLo(lo.size()+1);
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i+1]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i+1]=pre;
	}
	if(hi.size()==1){
		cout<<preLo[n]<<endl;
	}else if(lo.size()==1){
		cout<<preHi[1]<<endl;
	}else{
		while(preLo.size()<=n){
			preLo.push_back(preLo.back());
		}
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left<=n){
				ans = max(ans , preHi[take]+ preLo[left]);
			}
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size()+1);
	vector<ll> preLo(lo.size()+1);
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i+1]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i+1]=pre;
	}
	if(preHi.size()==1){
		cout<<preLo[n]<<endl;
	}else if(preLo.size()==1){
		cout<<preHi[1]<<endl;
	}else{
		while(preLo.size()<=n){
			preLo.push_back(preLo.back());
		}
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left<=n){
				ans = max(ans , preHi[take]+ preLo[left]);
			}
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}else if(lo.size()==0){
		cout<<preHi[0]<<endl;
	}else{
		ll ans = 0;
		for(int take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>lo.size())ans = max(ans , preHi[take-1] + preLo[lo.size()-1]);
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}else if(lo.size()==0){
		cout<<preHi[0]<<endl;
	}else{
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>lo.size())ans = max(ans , preHi[take-1] + preLo[lo.size()-1]);
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int MAXN = 46341 + 1;
int spf[46341+1];
int d,x,y;
int gcd(int a , int b){
	if(b==0)return a;
	return gcd(b , a%b);
}
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
ll gcd(ll a , ll b){
	if(b==0)return a;
	return gcd(b , a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

int cost(int x ,int y){
	return ((~x)&y);
}
int solve_(int i , int curr ,vector<  vector<int> >&dp, vector< vector<int> >&v){
	if(i==v.size())return 0;
	int& ret =dp[i][curr];
	if(~ret)return ret;
	ret = INT_MAX;
	for(int j = 0 ; j<v.size();j++){
		ret = min(ret , cost(curr , v[i][j]) + solve_(i+1 , curr|v[i][j] , dp ,v));
	}
	return ret;
}

void solve(){
	ll n ,m , d;
	cin>>n>>d>>m;
	vector<ll> a(n);
	vector<ll> pre(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++){
		if(i==0)pre[i]=a[i];
		else pre[i]=pre[i-1]+a[i];
	}
	int j = 0 , i;
	ll ans = a[n-1];
	for(i=n-2;i>=0;i--){
		if(a[i]<=m){
			for(int k=j;k<=i;k++)ans+=a[k];
			break;
		}
		if(i-j < d){
			for(int k=j;k<=i;k++){
				if(a[k]>m)break;
				ans+=a[k];
			}
			break;
		}
		if(a[j+d]>m){
			for(int k=j;k<=i;k++){
				if(a[k]>m)break;
				ans+=a[k];
			}
			break;
		}
		if(a[j+d]<=m){
			ll cost=0;
			if(j>0)cost = pre[j+d-1]-pre[j-1];
			else cost = pre[j+d-1];

			if(cost<=a[i])ans+=a[i], j+=d;
		}
	}
	cout<<ans;
}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;
	}
	// else if(lo.size()==0){
	// 	cout<<preHi[0]<<endl;

	// 	if(preHi[0] == 999991238){
	// 		cout<<lo.size()<<" "<<hi.size()<<endl;
	// 	}
	// }
	else{
		ll ans = 0;

		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>lo.size() && lo.size()>0)ans = max(ans , preHi[take-1] + preLo.back());
			else if(left>0 && lo.size()>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;

		if(preLo[n-1] == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}else if(lo.size()==0){
		cout<<preHi[0]<<endl;

		if(preHi[0] == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}else{
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>=lo.size())ans = max(ans , preHi[take-1] + preLo.back());
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
		if(ans == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;

		if(preLo[n-1] == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}
	// else if(lo.size()==0){
	// 	cout<<preHi[0]<<endl;

	// 	if(preHi[0] == 999991238){
	// 		cout<<lo.size()<<" "<<hi.size()<<endl;
	// 	}
	// }
	else{
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>lo.size())ans = max(ans , preHi[take-1] + preLo.back());
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
		if(ans == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}

void solve(){
	ll n,d,m;
	cin>>n>>d>>m;
	vector<ll>v(n);
	priority_queue<ll, vector<ll>, greater<ll> >ok;
	priority_queue<ll>hi;
	for(int i =0;i<n;i++){
		cin>>v[i];
		if(v[i]>m){
			hi.push(v[i]);
		}else{
			ok.push(v[i]);
		}
	}
	ll ans = 0,left=n;
	if(hi.size()>0){
		ans += hi.top();
		hi.pop();
		left--;
	}
	while(left>0){
		ll cost = 0;
		if(ok.size()>=d){
			set<ll>temp;
			int q =d;
			while(q--){
				cost += ok.top();
				temp.insert(ok.top());
				ok.pop();
			}
			if(hi.size()>0){
				if(hi.top()>cost){
					ans+=hi.top();
					hi.pop();
					left--;
				}else{
					for(auto x:temp)ok.push(x);
				}
			}else{
				ans+=cost;
			}
			left-=d;

		}else{
			while(ok.size()>0){
				ans += ok.top();
				ok.pop();
			}
			left = 0;
		}
	}
	cout<<ans<<endl;
}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}
void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll n , m, d;
	cin>>n>>d>>m;
	vector<ll>lo;
	vector<ll>hi;
	for(int i =0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp>m)hi.push_back(temp);
		else lo.push_back(temp);
	}
	sort(lo.rbegin(),lo.rend());
	sort(hi.rbegin(),hi.rend());
	vector<ll> preHi(hi.size());
	vector<ll> preLo(lo.size());
	ll pre = 0;
	for(int i = 0;i<hi.size();i++){
		pre+=hi[i];
		preHi[i]=pre;
	}
	pre=0;
	for(int i = 0;i<lo.size();i++){
		pre+=lo[i];
		preLo[i]=pre;
	}
	if(hi.size()==0){
		cout<<preLo[n-1]<<endl;

		if(ans == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}else if(lo.size()==0){
		cout<<preHi[0]<<endl;

		if(ans == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}else{
		ll ans = 0;
		for(ll take = 1;take<=hi.size();take++){
			ll left = n - (take-1)*(d+1) - 1;
			if(left<0 ){
				continue;
			}
			if(left>=lo.size())ans = max(ans , preHi[take-1] + preLo.back());
			else if(left>0)ans = max(ans , preHi[take-1] + preLo[left-1]);
			else ans = max(ans , preHi[take-1]);
		}
		cout<<ans<<endl;
		if(ans == 999991238){
			cout<<lo.size()<<" "<<hi.size()<<endl;
		}
	}

}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}


#define ll long long
#define lld long double
#define M 202
#define f first
#define s second
#define pi 3.141592653589793238
#define vl vector<ll>
#define pll pair<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define N 100002
#define Endl endl
#define maxx(a,b,c,d) max(max(a,b),max(d,c))
#define pb push_back
#define mod 1000000007
#define ss(v) sort(v.begin()+1,v.end())
#define sr(v) sort(v.begin()+1,v.end(),greater<ll>())
#define rin(A, B, C) (((A)<=(B))&&((B)<=(C)))
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll n,d,m;
	cin>>n>>d>>m;
	vl less,more;
	less.pb(0);more.pb(0);
	for(ll i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		if(a>m)more.pb(a);
		else less.pb(a);
	}
	sr(more);sr(less);
	vl pmore(more.size()),pless(less.size());
	for(ll i=1;i<pmore.size();i++)
	{
		pmore[i]+=more[i]+pmore[i-1];
	}
	for(ll i=1;i<pless.size();i++)
	{
		pless[i]+=less[i]+pless[i-1];
	}
	ll ans=0;
	for(ll i=0;i<more.size();i++)
	{
		ll res=0;
		ll gap=i-1;
		if(gap*d+i+d<more.size()-1)
		continue;
		else
		{
			res+=pmore[i];
			if(more.size()-1<(gap*d+i))
			{
				res+=pless[n-(gap*d+i)];
			}
			else
			{
				res+=pless[n];
			}

		}
		ans=max(ans,res);
	}
	cout<<ans;
	return 0;
}


#define ll long long
#define lld long double
#define M 202
#define f first
#define s second
#define pi 3.141592653589793238
#define vl vector<ll>
#define pll pair<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define N 100002
#define Endl endl
#define maxx(a,b,c,d) max(max(a,b),max(d,c))
#define pb push_back
#define mod 1000000007
#define ss(v) sort(v.begin()+1,v.end())
#define sr(v) sort(v.begin()+1,v.end(),greater<ll>())
#define rin(A, B, C) (((A)<=(B))&&((B)<=(C)))
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll n,d,m;
	cin>>n>>d>>m;
	vl less,more;
	less.pb(0);more.pb(0);
	for(ll i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		if(a>m)more.pb(a);
		else less.pb(a);
	}
	sr(more);sr(less);
	vl pmore(more.size(),0),pless(less.size(),0);
	for(ll i=1;i<pmore.size();i++)
	{
		pmore[i]+=more[i]+pmore[i-1];
	}
	for(ll i=1;i<pless.size();i++)
	{
		pless[i]+=less[i]+pless[i-1];
	}
	ll ans=0;
	if(more.size()==1)
	{
		ans=pless[pless.size()-1];
	}
	for(ll i=1;i<more.size();i++)
	{
		ll res=0;
		ll gap=i-1;
		if(gap*d+i+d<more.size()-1)
		continue;
		else
		{
			res+=pmore[i];
			if(more.size()-1<(gap*d+i))
			{
				res+=pless[n-(gap*d+i)];
			}
			else
			{
				res+=pless[pless.size()-1];
			}

		}
		ans=max(ans,res);
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	rep(i,0,n)	if (rev[i]>i)	swap(a[i],a[rev[i]]);
	for(ll d=1;d<n;d<<=1){
		E wn(cos(pi/d),f*sin(pi/d));
		for(ll i=0;i<n;i+=d<<1){
			E w(1,0),x,y;
			rep(j,0,d){
				x=a[i+j],y=a[i+j+d];
				a[i+j]=x+y;
				a[i+j+d]=x-y;
				w*=wn;
			}
		}
	}if (f==-1)	rep(i,0,n)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i-1]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
//	rep(i,0,n)	writeln(has[i]);
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		for(ll i=1;i<=len;i++){
			bool fl=1;
			for(ll j=i;j<len;j+=i)	if (has[len-1-i]||has[len-1+i])	fl=0;
			if (fl)ans[++tot]=i;
		}
		writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=500100;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	rep(i,0,n)	if (rev[i]>i)	swap(a[i],a[rev[i]]);
	for(ll d=1;d<n;d<<=1){
		E wn(cos(pi/d),f*sin(pi/d));
		for(ll i=0;i<n;i+=d<<1){
			E w(1,0),x,y;
			rep(j,0,d){
				x=a[i+j],y=a[i+j+d];
				a[i+j]=x+y;
				a[i+j+d]=x-y;
				w*=wn;
			}
		}
	}if (f==-1)	rep(i,0,n)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i-1]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		For(i,1,len){
			bool fl=1;
			for(ll j=i-1;j<=n;j+=i)	fl&=!has[j];
			if (fl)ans[++tot]=i;
		}writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	For(i,0,n-1)	if (i<rev[i])	swap(a[i],a[rev[i]]);
	for(ll i=1;i<n;i<<=1)	For(j,0,i-1){
		E wn(cos(pi/i*j),f*sin(pi/i*j));
		for(ll k=j;k<n;k+=i<<1){
			E x=a[k],y=wn*a[k+i];
			a[k]=x+y;	a[k+i]=x-y;
		}
	}if (f==-1)	For(i,0,n-1)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<=len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
//	rep(i,0,n)	writeln(a[i].real());
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		for(ll i=2;i<=2;i++){
			bool fl=1;
			for(ll j=i;j<=len;j+=i)		fl&=!has[len-j]&&!has[len+j];
			if (fl)	ans[++tot]=i;
		}
		writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

f[i-j]|=a[i]*b[j]
f[i-j+n]|=a[i]*b[j]
f[i+(n-j)]=a[i]*b[j]
f[i+rev[j]]=a[i]*rev_b[j]

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	rep(i,0,n)	if (rev[i]>i)	swap(a[i],a[rev[i]]);
	for(ll d=1;d<n;d<<=1){
		E wn(cos(pi/d),f*sin(pi/d));
		for(ll i=0;i<n;i+=d<<1){
			E w(1,0),x,y;
			rep(j,0,d){
				x=a[i+j],y=a[i+j+d];
				a[i+j]=x+y;
				a[i+j+d]=x-y;
				w*=wn;
			}
		}
	}if (f==-1)	rep(i,0,n)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i-1]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		For(i,1,len){
			bool fl=1;
			for(ll j=i-1;j<=n;j+=i)	fl&=!has[j];
			if (fl)ans[++tot]=i;
		}writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	rep(i,0,n)	if (rev[i]>i)	swap(a[i],a[rev[i]]);
	for(ll d=1;d<n;d<<=1){
		E wn(cos(pi/d),f*sin(pi/d));
		for(ll i=0;i<n;i+=d<<1){
			E w(1,0),x,y;
			rep(j,0,d){
				x=a[i+j],y=a[i+j+d];
				a[i+j]=x+y;
				a[i+j+d]=x-y;
				w*=wn;
			}
		}
	}if (f==-1)	rep(i,0,n)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<=len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i]=1;
//	rep(i,0,n)	writeln(a[i].real());
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
//	rep(i,0,n)	writeln(has[i]);
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		for(ll i=1;i<=len;i++){
			bool fl=1;
			for(ll j=i;j<=len;j+=i)	fl&=!has[len-i]&&!has[len+i];
			if (fl)	ans[++tot]=i;
		}
		writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

f[i-j]|=a[i]*b[j]
f[i-j+n]|=a[i]*b[j]
f[i+(n-j)]=a[i]*b[j]
f[i+rev[j]]=a[i]*rev_b[j]

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	For(i,0,n-1)	if (i<rev[i])	swap(a[i],a[rev[i]]);
	for(ll i=1;i<n;i<<=1)	For(j,0,i-1){
		E wn(cos(pi/i*j),f*sin(pi/i*j));
		for(ll k=j;k<n;k+=i<<1){
			E x=a[k],y=wn*a[k+i];
			a[k]=x+y;	a[k+i]=x-y;
		}
	}if (f==-1)	For(i,0,n-1)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<=len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1),a[i]=b[i]=0;
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		if (n==1)
		for(ll i=1;i<=len;i++){
			bool fl=1;
			for(ll j=i;j<=len;j+=i)		fl&=!has[len-j]&&!has[len+j];
			if (fl)	ans[++tot]=i;
		}
		writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

f[i-j]|=a[i]*b[j]
f[i-j+n]|=a[i]*b[j]
f[i+(n-j)]=a[i]*b[j]
f[i+rev[j]]=a[i]*rev_b[j]

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	rep(i,0,n)	if (rev[i]>i)	swap(a[i],a[rev[i]]);
	for(ll d=1;d<n;d<<=1){
		E wn(cos(pi/d),f*sin(pi/d));
		for(ll i=0;i<n;i+=d<<1){
			E w(1,0),x,y;
			rep(j,0,d){
				x=a[i+j],y=a[i+j+d];
				a[i+j]=x+y;
				a[i+j+d]=x-y;
				w*=wn;
			}
		}
	}if (f==-1)	rep(i,0,n)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
//	memset(a,0,sizeof a);
//	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i-1]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
//	rep(i,0,n)	writeln(has[i]);
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		For(i,1,len){
			bool fl=1;
			for(ll j=i;j<=n;j+=i){
				if (len-1-j>=0)	fl&=!has[len-1-j];
				if (len-1+j>=0)	fl&=!has[len-1+j];
			}if (fl)ans[++tot]=i;
		}writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define fi first
#define se second
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define EXIT(x)	return writeln(x),0;
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    const int L=2333333;
    char SZB[L],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,L,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
}using namespace SHENZHEBEI;
const ll N=1200000;
E a[N],b[N];	char s[N];
ll rev[N],ans[N],n,len,has[N],tot;
void dft(E *a,ll f){
	For(i,0,n-1)	if (i<rev[i])	swap(a[i],a[rev[i]]);
	for(ll i=1;i<n;i<<=1)	For(j,0,i-1){
		E wn(cos(pi/i*j),f*sin(pi/i*j));
		for(ll k=j;k<n;k+=i<<1){
			E x=a[k],y=wn*a[k+i];
			a[k]=x+y;	a[k+i]=x-y;
		}
	}if (f==-1)	For(i,0,n-1)	a[i]/=n;
}
void work(){
	ll hh=0;
	for(n=1;n<=len*2;n<<=1)	++hh;
	rep(i,0,n)	rev[i]=(rev[i>>1]>>1)|((i&1)<<hh-1);
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	rep(i,0,len)	if (s[i]=='V')	a[i]=1;
	rep(i,0,len)	if (s[i]=='K')	b[len-i]=1;
	dft(a,1);	dft(b,1);	rep(i,0,n)	a[i]*=b[i];	dft(a,-1);
	rep(i,0,n)	has[i]=(ll)(a[i].real()+0.5)>0;
//	rep(i,0,n)	writeln(has[i]);
}
int main(){
	ll T=read();
	while(T--){
		len=read();	readstr(s);	work();	tot=0;
		for(ll i=1;i<=len;i++){
			bool fl=1;
			for(ll j=i;j<=len;j+=i)	fl&=!has[len-i]&&!has[len+i];
			if (fl)	ans[++tot]=i;
		}
		writeln(tot);	For(i,1,tot)	printf("%I64d ",ans[i]);	puts("");
	}
}
/*

	10010
*	10000
---------
	10010

f[i-j]|=a[i]*b[j]
f[i-j+n]|=a[i]*b[j]
f[i+(n-j)]=a[i]*b[j]
f[i+rev[j]]=a[i]*rev_b[j]

*/


#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 1048577 , mo = 998244353 , gmo = 3 , igmo = 332748118;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int rev[_];

int nttmake(int n)
{
	int nn=1,lg=0;
	while(nn<n)nn<<=1,lg++;
	rev[0]=0;
	for(int i=1;i<nn;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg-1));
	return nn;
}

void ntt(lint a[],int nn,int dir)
{
	for(int i=0;i<nn;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<nn;i<<=1)
		for(int j=0,g=powa(dir>0?gmo:igmo,(mo-1)/(i+i));j<nn;j+=i+i)
			for(int k=0,x,y,ig=1;k<i;k++,ig=1ll*ig*g%mo)
				x=a[j+k],y=a[j+k+i]*ig%mo,a[j+k]=add(x,y),a[j+k+i]=del(x,y);
	if(dir<0)for(int i=0,x=inva(nn);i<nn;i++)a[i]=a[i]*x%mo;
}

inline int c2i(int c){if(c=='V')return 0;if(c=='K')return 1;return -1;}

int n,str[_];
lint pa[_],pb[_];
vector<int> ans;

void finder()
{
	n=ty(),ts(str);
	for(int i=0;i<n;i++)str[i]=c2i(str[i]);

	int nn=nttmake(n+n-1);
	for(int i=0;i<nn;i++)pa[i]=pb[i]=0;
	for(int i=0;i<n;i++){if(str[i]==1)pa[i]=1;if(str[i]==0)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);

	ans.clear();
	for(int i=1;i<=n;i++)
	{
		int got=1;
		for(int j=i;got && j<=n;j+=i)if(pa[n-j-1] || pa[n+j-1])got=0;
		if(got)ans.emplace_back(i);
	}

	cout<<ans.size()<<lf;
	for(auto i:ans)cout<<i<<' ';
	cout<<lf;
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	int t=ty();
	while(t--)finder();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 1048579 , mo = 998244353 , gmo = 3 , igmo = 332748118;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int rev[_];

int nttmake(int n)
{
	int nn=1,lg=0;
	while(nn<n)nn<<=1,lg++;
	rev[0]=0;
	for(int i=1;i<nn;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg-1));
	return nn;
}

void ntt(lint a[],int nn,int dir)
{
	for(int i=0;i<nn;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<nn;i<<=1)
		for(int j=0,g=powa(dir>0?gmo:igmo,(mo-1)/(i+i));j<nn;j+=i+i)
			for(int k=0,x,y,ig=1;k<i;k++,ig=1ll*ig*g%mo)
				x=a[j+k],y=a[j+k+i]*ig%mo,a[j+k]=add(x,y),a[j+k+i]=del(x,y);
	if(dir<0)for(int i=0,x=inva(nn);i<nn;i++)a[i]=a[i]*x%mo;
}

inline int c2i(int c){if(c=='V')return 0;if(c=='K')return 1;return -1;}

int n,str[_];
lint pa[_],pb[_];
vector<int> ans;

void finder()
{
	n=ty(),ts(str);
	for(int i=0;i<n;i++)str[i]=c2i(str[i]);

	int nn=nttmake(n+n-1);
	for(int i=0;i<nn;i++)pa[i]=pb[i]=0;
	for(int i=0;i<n;i++){if(str[i]==1)pa[i]=1;if(str[i]==0)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);

	ans.clear();
	for(int i=1;i<=n;i++)
	{
		int got=1;
		for(int j=i;got && j<=n;j+=i)
			if(pa[n+j-1] || (j<n?pa[n-j-1]:0))got=0;
		if(got)ans.emplace_back(i);
	}

	cout<<ans.size()<<lf;
	for(auto i:ans)cout<<i<<' ';
	cout<<lf;
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	int t=ty();
	while(t--)finder();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 1048579 , mo = 998244353 , gmo = 3 , igmo = 332748118;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int rev[_];

int nttmake(int n)
{
	int nn=1,lg=0;
	while(nn<n)nn<<=1,lg++;
	rev[0]=0;
	for(int i=1;i<nn;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg-1));
	return nn;
}

void ntt(lint a[],int nn,int dir)
{
	for(int i=0;i<nn;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<nn;i<<=1)
		for(int j=0,g=powa(dir>0?gmo:igmo,(mo-1)/(i+i));j<nn;j+=i+i)
			for(int k=0,x,y,ig=1;k<i;k++,ig=1ll*ig*g%mo)
				x=a[j+k],y=a[j+k+i]*ig%mo,a[j+k]=add(x,y),a[j+k+i]=del(x,y);
	if(dir<0)for(int i=0,x=inva(nn);i<nn;i++)a[i]=a[i]*x%mo;
}

inline int c2i(int c){if(c=='V')return 0;if(c=='K')return 1;return -1;}

int n,str[_];
lint pa[_],pb[_],pc[_];
vector<int> ans;

void finder()
{
	n=ty(),ts(str);
	for(int i=0;i<n;i++)str[i]=c2i(str[i]);

	int nn=nttmake(n+n-1);
	for(int i=0;i<nn;i++)pa[i]=pb[i]=pc[i]=0;
	for(int i=0;i<n;i++){if(str[i]==1)pa[i]=1;if(str[i]==0)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);
	for(int i=0;i<nn;i++)pc[i]=pa[i];

	for(int i=0;i<nn;i++)pa[i]=pb[i]=0;
	for(int i=0;i<n;i++){if(str[i]==0)pa[i]=1;if(str[i]==1)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);
	for(int i=0;i<nn;i++)ad(pc[i],pa[i]);

	ans.clear();
	for(int i=1;i<=n;i++)
	{
		int got=1;
		for(int j=i;got && j<=n;j+=i)if(pc[n+j-1])got=0;
		if(got)ans.emplace_back(i);
	}

	cout<<ans.size()<<lf;
	for(auto i:ans)cout<<i<<' ';
	cout<<lf;
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	int t=ty();
	while(t--)finder();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 1048579 , mo = 998244353 , gmo = 3 , igmo = 332748118;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int rev[_];

int nttmake(int n)
{
	int nn=1,lg=0;
	while(nn<n)nn<<=1,lg++;
	rev[0]=0;
	for(int i=1;i<nn;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg-1));
	return nn;
}

void ntt(lint a[],int nn,int dir)
{
	for(int i=0;i<nn;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<nn;i<<=1)
		for(int j=0,g=powa(dir>0?gmo:igmo,(mo-1)/(i+i));j<nn;j+=i+i)
			for(int k=0,x,y,ig=1;k<i;k++,ig=1ll*ig*g%mo)
				x=a[j+k],y=a[j+k+i]*ig%mo,a[j+k]=add(x,y),a[j+k+i]=del(x,y);
	if(dir<0)for(int i=0,x=inva(nn);i<nn;i++)a[i]=a[i]*x%mo;
}

inline int c2i(int c){if(c=='V')return 0;if(c=='K')return 1;return -1;}

int n,str[_];
lint pa[_],pb[_],pc[_];
vector<int> ans;

void finder()
{
	n=ty(),ts(str);
	for(int i=0;i<n;i++)str[i]=c2i(str[i]);

	int nn=nttmake(n+n-1);
	for(int i=0;i<nn;i++)pa[i]=pb[i]=pc[i]=0;
	for(int i=0;i<n;i++){if(str[i]==1)pa[i]=1;if(str[i]==0)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);
	for(int i=0;i<nn;i++)pc[i]=pa[i];

	for(int i=0;i<nn;i++)pa[i]=pb[i]=0;
	for(int i=0;i<n;i++){if(str[i]==0)pa[i]=1;if(str[i]==1)pb[i]=1;}
	reverse(pa,pa+n);
	ntt(pa,nn,1),ntt(pb,nn,1);
	for(int i=0;i<nn;i++)pa[i]=pa[i]*pb[i]%mo;
	ntt(pa,nn,-1);
	for(int i=0;i<nn;i++)ad(pc[i],pa[i]);

	ans.clear();
	for(int i=1;i<=n;i++)
	{
		int got=1;
		for(int j=i;got && j<n;j+=i)if(pc[n-j-1])got=0;
		if(got)ans.emplace_back(i);
	}

	cout<<ans.size()<<lf;
	for(auto i:ans)cout<<i<<' ';
	cout<<lf;
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	int t=ty();
	while(t--)finder();

	return 0;
}


/*
* Filename:    cf827e.cpp
* Created:     2017年07月19日 21时50分37秒 星期三
* Author:      ineedAC
*
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;

//           FFT           //
const int N= (1 << 20);
//复数类
typedef double ld;
const ld PI=acos(-1);
struct Virt
{
	ld r,i;
	Virt(ld r=0.0,ld i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(ld)n;
}
//  求a,b的卷积
Virt FA[N], FB[N];
inline void Convolution(ld a[], int n, ld b[], int m, ld c[], int &len)
{
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
char s[N];
ld a[N],b[N],c[N];
bool can[N];
int n,m,T;
int ans[N];

void print(ld x[],int len){
	return;
	for (int i = 0; i < len; i += 1)
		printf("%.1f\t",x[i]);
	puts("");
}
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='?')a[i]=b[i]=0;
			else a[i]=b[i]=1;
		reverse(a,a+n);
		Convolution(a,n,b,n,c,m);
		print(a,n);print(b,n);print(c,m);

		for (int i = 0; i < n; i += 1)
			if(s[i]=='V')a[i]=b[i]=1;
			else if(s[i]=='K')a[i]=b[i]=-1;
			else a[i]=b[i]=0;

		reverse(a,a+n);
		print(a,n);print(b,n);
		Convolution(a,n,b,n,b,m);
		print(b,m);

		for (int p = n; p >= 1; p += -1){
			int pp=n-1+p;
			can[p]=false;
			if(int(c[pp]+0.5)==(int)(b[pp]+0.5))can[p]=true;
//			if(p>n/2&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
//				can[p]=true;
//			if(p<=n/2&&can[p*2]&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
//				can[p]=true;
		}
//
//		for (int i = 1; i <= n; i += 1)
//			printf("%d  ",can[i]);
//		puts("");
//
		for (int i = n; i >= 1; i += -1){
			for (int j = i+i; j <= n; j += i){
				if(!can[j]){
					can[i]=false;
					break;
				}
			}
		}

		int cnt=0;

		for (int i = 1; i <= n; i += 1)
			if(can[i])ans[cnt++]=i;
//		if(cnt==n-1&&can[1]){
//			printf("%d\n%d ",cnt+1,1);
//		}else

		printf("%d\n",cnt);

		for (int i = 0; i < cnt; i += 1)
			printf("%d%c",ans[i],i==cnt-1?'\n':' ');
	}
	return 0;
}


/*
* Filename:    cf827E.cpp
* Created:     2017年07月12日 15时57分02秒 星期三
* Author:      ineedAC
* FFT
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
const int INF=998244353-7;
const int maxn=5e5+7;
//           FFld           //
typedef double ld;
//复数类
const int MAXN = 1 << 20;
struct cplex {
    ld r, i;
    cplex() : r(0), i(0) {}
    cplex(ld n) : r(n), i(0) {}
    cplex(ld r, ld i) : r(r), i(i) {}
    ld real() {return r;}
    cplex operator + (cplex b) {return cplex (r + b.r, i + b.i);}
    cplex operator += (cplex b) {r += b.r, i += b.i; return *this;}
    cplex operator - (cplex b) {return cplex(r - b.r, i - b.i);}
    cplex operator * (cplex b) {return cplex(r * b.r - i * b.i, r * b.i + i * b.r);}
    cplex operator *= (cplex b) {ld r2 = r * b.r - i * b.i, i2 = r * b.i + i * b.r; r = r2, i = i2; return *this;}
    cplex operator /= (ld n) {r /= n, i /= n; return *this;}
};
void fft(cplex a[], int n, int invert) {
    static ld PI = 2 * acos((ld) 0);
    for (int i = 1, j = 0; i < n; i++) {
        for (int s = n; j ^= s >>= 1, ~j & s;);
        if (i < j) swap(a[i], a[j]);
    }
    for (int m = 1; m < n; m <<= 1) {
        ld p = PI / m * (invert ? -1 : 1);
        cplex w = cplex(cos(p), sin(p));
        for (int i = 0; i < n; i += m << 1) {
            cplex unit = 1;
            for (int j = 0; j < m; j++) {
                cplex& x = a[i + j + m], &y = a[i + j], t = unit * x;
                x = y - t;
                y = y + t;
                unit *= w;
            }
        }
    }
    if (invert) for (int i = 0; i < n; i++) a[i] /= n;
}
void multiply(int a[], int b[], int c[], int na, int nb) {
    static cplex fa[MAXN << 1], fb[MAXN << 1];
    int n = 1; while (n < na + nb - 1) n <<= 1;
    for (int i = 0; i < n; i++) fa[i] = fb[i] = cplex(0);
    for (int i = 0; i < na; i++) fa[i] = cplex(a[i]);
    for (int i = 0; i < nb; i++) fb[i] = cplex(b[i]);
    fft(fa, n, 0); fft(fb, n, 0);
    for (int i = 0; i < n; i++) fa[i] *= fb[i];
    fft(fa, n, 1);
    for (int i = 0; i < n; i++) c[i] = (long long) (fa[i].real() + 0.5);
}
//           FFT           //
int A[maxn*2],B[maxn];
int C[maxn*2];

void out(ld a[],ld b[],int n){
	cout<<"A: ";
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	cout<<endl;
	cout<<"B: ";
	for(int i=0;i<n;i++)cout<<b[i]<<" ";
	cout<<endl;
}
int n,m,T;
char s[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	freopen("fft.out","w",stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		for(int i=0;i<n;i++)
			if(s[i]=='?')B[i]=A[i]=0;
			else B[i]=A[i]=1;
		reverse(B,B+n);
//		out(A,B,n);
//		puts("--------");
		multiply(A,B,C,n,n);
		for(int i=0;i<n;i++)
			if(s[i]=='V')A[i]=-1,B[n-1-i]=-1;

//		out(A,B,n);
//		puts("--------");puts("--------");
		multiply(A,B,A,n,n);
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

//		for(int i=0;i<2*n;i++){
//			if(C2[i]>INF)C2[i]=-1;
//		}
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		int cnt=0;
		char aim='?';
		bool can=true;
		for(int i=0;i<n;i++){
			if(s[i]=='?'||s[i]==aim)continue;
			else{
				if(aim=='?')aim=s[i];
				else can=false;
			}
		}
		if(can)s[cnt++]=1;

		for(int i=n+1;i<2*n;i++){
			int v1=int(A[i]+0.5);
			int v2=int(C[i]+0.5);
			if(i-n+1<=n/2){
				int len=(i-n+1)*2;
				int nxp=len-1+n;
				int va1=int(A[nxp]+0.5);
				int va2=int(C[nxp]+0.5);
				if(v1==v2&&va1==va2)s[cnt++]=i-n+1;
			}
			else{
				if(v1==v2)s[cnt++]=i-n+1;
			}

		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++){
			if(i==cnt-1)printf("%d\n",s[i]);
			else printf("%d ",s[i]);
		}
	}
	return 0;
}


/*
* Filename:    cf827E.cpp
* Created:     2017年07月12日 15时57分02秒 星期三
* Author:      ineedAC
* FFT
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
const int INF=998244353-7;
const int maxn=5e5+7;
//           FFT           //
typedef double ld;
//复数类
const ld PI=acos(-1);
struct Virt
{
	ld r,i;
	Virt(ld r=0.0,ld i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(ld)n;
}
//  求a,b的卷积
const int N=4*maxn;
inline void Convolution(ld a[], int n, ld b[], int m, ld c[], int &len)
{
	static Virt FA[N], FB[N];
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
ld A[maxn],B[maxn];
ld C1[maxn],C2[maxn];

void out(ld a[],ld b[],int n){
	cout<<"A: ";
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	cout<<endl;
	cout<<"B: ";
	for(int i=0;i<n;i++)cout<<b[i]<<" ";
	cout<<endl;
}
int n,m,T;
char s[maxn];
int tmp[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	freopen("fft.out","w",stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		int len;
		for(int i=0;i<n;i++)
			if(s[i]=='?')B[i]=A[i]=0;
			else B[i]=A[i]=1;
		reverse(B,B+n);
//		out(A,B,n);
//		puts("--------");
		Convolution(A,n,B,n,C1,len);
		for(int i=0;i<n;i++)
			if(s[i]=='V')A[i]=-1,B[n-1-i]=-1;

//		out(A,B,n);
//		puts("--------");puts("--------");
		Convolution(A,n,B,n,C2,len);
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

//		for(int i=0;i<2*n;i++){
//			if(C2[i]>INF)C2[i]=-1;
//		}
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		int cnt=0;
		char aim='?';
		bool can=true;
		for(int i=0;i<n;i++){
			if(s[i]=='?'||s[i]==aim)continue;
			else{
				if(aim=='?')aim=s[i];
				else can=false;
			}
		}
		if(can)tmp[cnt++]=1;

		for(int i=n+1;i<2*n;i++){
			int v1=int(C1[i]+0.5);
			int v2=int(C2[i]+0.5);
			if(i-n+1<=n/2){
				int len=(i-n+1)*2;
				int nxp=len-1+n;
				int va1=int(C1[nxp]+0.5);
				int va2=int(C2[nxp]+0.5);
				if(v1==v2&&va1==va2)tmp[cnt++]=i-n+1;
			}
			else{
				if(v1==v2)tmp[cnt++]=i-n+1;
			}

		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++){
			if(i==cnt-1)printf("%d\n",tmp[i]);
			else printf("%d ",tmp[i]);
		}
	}
	return 0;
}


/*
* Filename:    cf827E.cpp
* Created:     2017年07月12日 15时57分02秒 星期三
* Author:      ineedAC
* FFT
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
const int INF=998244353-7;
const int maxn=5e5+7;
//           FFT           //
typedef double ld;
//复数类
const ld PI=acos(-1);
struct Virt
{
	ld r,i;
	Virt(ld r=0.0,ld i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(ld)n;
}
//  求a,b的卷积
const int N=2*maxn;
inline void Convolution(ld a[], int n, ld b[], int m, ld c[], int &len)
{
	static Virt FA[N], FB[N];
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
ld A[maxn],B[maxn];
ld C1[maxn],C2[maxn];

void out(ld a[],ld b[],int n){
	cout<<"A: ";
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	cout<<endl;
	cout<<"B: ";
	for(int i=0;i<n;i++)cout<<b[i]<<" ";
	cout<<endl;
}
int n,m,T;
char s[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	freopen("fft.out","w",stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		int len;
		for(int i=0;i<n;i++)
			if(s[i]=='?')B[i]=A[i]=0;
			else B[i]=A[i]=1;
		reverse(B,B+n);
//		out(A,B,n);
//		puts("--------");
		Convolution(A,n,B,n,C1,len);
		for(int i=0;i<n;i++)
			if(s[i]=='V')A[i]=-1,B[n-1-i]=-1;

//		out(A,B,n);
//		puts("--------");puts("--------");
		Convolution(A,n,B,n,C2,len);
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

//		for(int i=0;i<2*n;i++){
//			if(C2[i]>INF)C2[i]=-1;
//		}
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		int cnt=0;
		char aim='?';
		bool can=true;
		for(int i=0;i<n;i++){
			if(s[i]=='?'||s[i]==aim)continue;
			else{
				if(aim=='?')aim=s[i];
				else can=false;
			}
		}
		if(can)s[cnt++]=1;

		for(int i=n+1;i<2*n;i++){
			int v1=int(C1[i]+0.5);
			int v2=int(C2[i]+0.5);
			if(i-n+1<=n/2){
				int len=(i-n+1)*2;
				int nxp=len-1+n;
				int va1=int(C1[nxp]+0.5);
				int va2=int(C2[nxp]+0.5);
				if(v1==v2&&va1==va2)s[cnt++]=i-n+1;
			}
			else{
				if(v1==v2)s[cnt++]=i-n+1;
			}

		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++){
			if(i==cnt-1)printf("%d\n",s[i]);
			else printf("%d ",s[i]);
		}
	}
	return 0;
}


/*
* Filename:    cf827e.cpp
* Created:     2017年07月19日 21时50分37秒 星期三
* Author:      ineedAC
*
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;

//           FFT           //
const int N= (1 << 20);
//复数类
const double PI=acos(-1);
struct Virt
{
	double r,i;
	Virt(double r=0.0,double i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(double)n;
}
//  求a,b的卷积
Virt FA[N], FB[N];
inline void Convolution(double a[], int n, double b[], int m, double c[], int &len)
{
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
char s[N];
double a[N],b[N],c[N];
bool can[N];
int n,m,T;
int ans[N];

void print(double x[],int len){
	return;
	for (int i = 0; i < len; i += 1)
		printf("%.1f\t",x[i]);
	puts("");
}
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='?')a[i]=b[i]=0;
			else a[i]=b[i]=1;
		reverse(a,a+n);
		Convolution(a,n,b,n,c,m);
		print(a,n);print(b,n);print(c,m);

		for (int i = 0; i < n; i += 1)
			if(s[i]=='V')a[i]=b[i]=1;
			else if(s[i]=='K')a[i]=b[i]=-1;
			else a[i]=b[i]=0;

		reverse(a,a+n);
		print(a,n);print(b,n);
		Convolution(a,n,b,n,b,m);
		print(b,m);

		for (int p = n; p >= 1; p += -1){
			int pp=n-1+p;
			can[p]=false;
			if(int(c[pp]+0.5)==(int)(b[pp]+0.5))can[p]=true;
//			if(p>n/2&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
//				can[p]=true;
//			if(p<=n/2&&can[p*2]&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
//				can[p]=true;
		}
		for (int i = n; i >= 1; i += -1){
			for (int j = i+i; j <= n; j += 1){
				can[i] |= can[j];
			}
		}

		int cnt=0;

		for (int i = 2; i <= n; i += 1)
			if(can[i])ans[cnt++]=i;
//		if(cnt==n-1&&can[1]){
//			printf("%d\n%d ",cnt+1,1);
//		}else

		printf("%d\n",cnt);

		for (int i = 0; i < cnt; i += 1)
			printf("%d%c",ans[i],i==cnt-1?'\n':' ');
	}
	return 0;
}


/*
* Filename:    cf827e.cpp
* Created:     2017年07月19日 21时50分37秒 星期三
* Author:      ineedAC
*
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;

//           FFT           //
const int N= (1 << 18);
//复数类
const double PI=acos(-1);
struct Virt
{
	double r,i;
	Virt(double r=0.0,double i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(double)n;
}
//  求a,b的卷积
inline void Convolution(double a[], int n, double b[], int m, double c[], int &len)
{
	static Virt FA[N], FB[N];
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
char s[N];
double a[N],b[N],c[N];
bool can[N];
int n,m,T;
int ans[N];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='?')a[i]=b[i]=0;
			else a[i]=b[i]=1;
		reverse(a,a+n);
		Convolution(a,n,b,n,c,m);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='V')b[i]=1;
			else if(s[i]=='K')b[i]=-1;
			else b[i]=0;
		Convolution(a,n,b,n,b,m);
		for (int p = n; p >= 1; p += -1){
			can[p]=false;
			int pp=n-1+p;
			if(p>n/2&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
				can[p]=true;
			if(p<=n/2&&can[p*2]&&int(c[pp]+0.5)==(int)(b[pp]+0.5))
				can[p]=true;
		}
		int cnt=0;
		for (int i = 1; i <= n; i += 1)
			if(can[i])ans[cnt++]=i;
		printf("%d\n",cnt);
		for (int i = 0; i < cnt; i += 1)
			printf("%d%c",ans[i],i==cnt-1?'\n':' ');
	}
	return 0;
}


/*
* Filename:    cf827E.cpp
* Created:     2017年07月12日 15时57分02秒 星期三
* Author:      ineedAC
* FFT
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;
const int maxn=5e5+7;
const int N=4*maxn;
//           NTT          //
const ll P = 50000000001507329LL; //190734863287 * 2 ^ 18 + 1, g = 3
const int G = 3; //P的原根
ll Wn[25],nWn[25];
long long mul(long long x,long long y){
  return (x*y-(long long)(x/(long double)P*y+1e-3)*P+P)%P;
}
inline ll qpow(ll a, ll b)
{
    ll re = 1;
    for(; b; b >>= 1, a = mul(a,a))
        if(b & 1)   re = mul(re,a);
    return re;
}
#define INV(x)  (qpow(x, P - 2))
inline void GetWn()
{
    for(int i = 0; i < 25; i++){
        Wn[i] = qpow(G, (P - 1) / (1 << i));
        nWn[i] = INV(Wn[i]);
    }
}

inline void Rader(ll F[], int n)
{
    int j = n >> 1;
    for(int i = 1; i < n - 1; i++)
    {
        if(i < j)   swap(F[i], F[j]);
        int k = n >> 1;
        while(j >= k)   j -= k, k >>= 1;
        if(j < k)   j += k;
    }
}
inline void NTT(ll F[], int n, int flag)
{
    Rader(F, n);    int id = 0;
    for(int h = 2; h <= n; h <<= 1)
    {
        ll wn = flag == 1 ? Wn[++id] : nWn[++id];
        for(int i = 0; i < n; i += h)
        {
            ll w = 1;
            for(int j = i; j < i + h / 2; j++)
            {
                ll u = F[j];
				ll v=mul(w,F[j+h/2]);
                F[j] = (u + v) % P;
                F[j + h / 2] = (u - v + P) % P;
				w=mul(w,wn);
            }
        }
    }
    if(flag == -1)
    {
        ll inv = INV(n);
        for(int i = 0; i < n; i++)  F[i] = mul(F[i],inv);
    }
}
inline void Convolution(ll a[], int n, ll b[], int m, ll c[], int &len)
{
    static ll FA[N], FB[N];
    int i;  len = 1;    GetWn();
    for(; len < n * 2 || len < m * 2; len <<= 1);
    for(i = 0; i < n; i++)  FA[i] = a[i];
    for(; i < len; i++) FA[i] = 0;
    for(i = 0; i < m; i++)  FB[i] = b[i];
    for(; i < len; i++) FB[i] = 0;

    NTT(FA, len, 1);    NTT(FB, len, 1);
    for(i = 0; i < len; i++) FA[i] = mul(FA[i],FB[i]);
    NTT(FA, len, -1);

    for(i = 0; i < len; i++)    c[i] = FA[i];
}
//           NTT          //
ll A[maxn],B[maxn];
ll C1[maxn],C2[maxn];

void out(ll a[],ll b[],int n){
	cout<<"A: ";
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	cout<<endl;
	cout<<"B: ";
	for(int i=0;i<n;i++)cout<<b[i]<<" ";
	cout<<endl;
}
int n,m,T;
char s[maxn];
int tmp[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		int len;
		for(int i=0;i<n;i++)
			if(s[i]=='?')B[i]=A[i]=0;
			else B[i]=A[i]=1;
		reverse(B,B+n);
//		out(A,B,n);
//		puts("--------");
		Convolution(A,n,B,n,C1,len);
		for(int i=0;i<n;i++)
			if(s[i]=='V')A[i]=-1,B[n-1-i]=-1;

//		out(A,B,n);
//		puts("--------");puts("--------");
		Convolution(A,n,B,n,C2,len);
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		for(int i=0;i<2*n;i++){
			if(C2[i]>INF)C2[i]=-1;
		}
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		int cnt=0;
		for(int i=n;i<2*n;i++){
			if(i-n+1<=n/2){
				int len=(i-n+1)*2;
				int nxp=len-1+n;
				if(C1[i]==C2[i]&&C1[nxp]==C2[nxp])tmp[cnt++]=i-n+1;
			}
			else{
				if(C1[i]==C2[i])tmp[cnt++]=i-n+1;
			}

		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++){
			if(i==cnt-1)printf("%d\n",tmp[i]);
			else printf("%d ",tmp[i]);
		}
	}
	return 0;
}


/*
* Filename:    cf827e.cpp
* Created:     2017年07月19日 21时50分37秒 星期三
* Author:      ineedAC
*
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;

//           FFT           //
const int N= (1 << 20);
typedef double ld;
//复数类
const ld PI=acos(-1);
struct Virt
{
	ld r,i;
	Virt(ld r=0.0,ld i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(ld)n;
}
//  求a,b的卷积
inline void Convolution(ld a[], int n, ld b[], int m, ld c[], int &len)
{
	static Virt FA[N], FB[N];
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
char s[N];
ld a[N],b[N],c[N],d[N];
bool can[N];
vector<int> ans;
int n,m,T;
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='?')a[i]=b[i]=0;
			else a[i]=b[i]=1;
		reverse(a,a+n);
		Convolution(a,n,b,n,c,m);
		for (int i = 0; i < n; i += 1)
			if(s[i]=='V')b[i]=1;
			else if(s[i]=='K')b[i]=-1;
			else b[i]=0;
		Convolution(a,n,b,n,d,m);
		for (int p = n; p >= 1; p += -1){
			can[p]=false;
			int pp=n-1+p;
			if(p>n/2&&int(c[pp]+0.5)==(int)(d[pp]+0.5))
				can[p]=true;
			if(p<=n/2&&can[p*2]&&int(c[pp]+0.5)==(int)(d[pp]+0.5))
				can[p]=true;
		}
		ans.clear();
		for (int i = 1; i <= n; i += 1)
			if(can[i])ans.pb(i);
		printf("%d\n",SZ(ans));
		for (int i = 0; i < SZ(ans); i += 1)
			printf("%d%c",ans[i],i==SZ(ans)-1?'\n':' ');
	}
	return 0;
}


/*
* Filename:    cf827E.cpp
* Created:     2017年07月12日 15时57分02秒 星期三
* Author:      ineedAC
* FFT
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
const int INF=998244353-7;
const int maxn=5e5+7;
//           FFT           //
typedef long double ld;
//复数类
const ld PI=acos(-1);
struct Virt
{
	ld r,i;
	Virt(ld r=0.0,ld i=0.0):r(r),i(i){}
	friend Virt operator - (const Virt &a, const Virt &b) { return Virt(a.r - b.r, a.i - b.i); }
	friend Virt operator + (const Virt &a, const Virt &b) { return Virt(a.r + b.r, a.i + b.i); }
	friend Virt operator * (const Virt &a, const Virt &b) { return Virt(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
};
inline void Rader(Virt F[], int n){
	int j=n>>1;
	for (int i = 1; i < n-1; i += 1){
		if(i<j)swap(F[i],F[j]);
		int k=n>>1;
		while(j>=k)j-=k,k>>=1;
		if(j<k)j+=k;
	}
}
inline void FFT(Virt F[],int n,int flag){
	Rader(F,n);
	for (int h = 2; h <= n; h <<= 1){
		Virt wn(cos(flag * 2 * PI / h), sin(flag * 2 * PI / h));
		for (int i = 0; i < n; i += h){
			Virt w(1,0);
			for (int j = i; j < i+h/2; j += 1){
				Virt u = F[j];
				Virt v = w * F[j + h / 2];
				F[j] = u + v;
				F[j + h / 2 ] = u - v;
				w = w* wn;
			}
		}
	}
	if(flag == -1)  for(int i = 0; i < n; i++)  F[i].r /=(ld)n;
}
//  求a,b的卷积
const int N=4*maxn;
inline void Convolution(ld a[], int n, ld b[], int m, ld c[], int &len)
{
	static Virt FA[N], FB[N];
	int i;  len = 1;
	while(len < 2 * n || len < 2 * m)   len <<= 1;
	for(i = 0; i < n; i++)  FA[i] = Virt(a[i]);
	for(; i < len; i++) FA[i] = Virt();
	for(i = 0; i < m; i++)  FB[i] = Virt(b[i]);
	for(; i < len; i++) FB[i] = Virt();

	FFT(FA, len, 1);    FFT(FB, len, 1);
	for(i = 0; i < len; i++)    FA[i] = FA[i] * FB[i];
	FFT(FA, len, -1);

	for(i = 0; i < len; i++)    c[i] = FA[i].r;
}
//           FFT           //
ld A[maxn],B[maxn];
ld C1[maxn],C2[maxn];

void out(ld a[],ld b[],int n){
	cout<<"A: ";
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	cout<<endl;
	cout<<"B: ";
	for(int i=0;i<n;i++)cout<<b[i]<<" ";
	cout<<endl;
}
int n,m,T;
char s[maxn];
int tmp[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	freopen("fft.out","w",stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%s",&n,s);
		int len;
		for(int i=0;i<n;i++)
			if(s[i]=='?')B[i]=A[i]=0;
			else B[i]=A[i]=1;
		reverse(B,B+n);
//		out(A,B,n);
//		puts("--------");
		Convolution(A,n,B,n,C1,len);
		for(int i=0;i<n;i++)
			if(s[i]=='V')A[i]=-1,B[n-1-i]=-1;

//		out(A,B,n);
//		puts("--------");puts("--------");
		Convolution(A,n,B,n,C2,len);
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

//		for(int i=0;i<2*n;i++){
//			if(C2[i]>INF)C2[i]=-1;
//		}
//		out(C1,C2,2*n);
//		puts("--------");puts("--------");

		int cnt=0;
		char aim='?';
		bool can=true;
		for(int i=0;i<n;i++){
			if(s[i]=='?'||s[i]==aim)continue;
			else{
				if(aim=='?')aim=s[i];
				else can=false;
			}
		}
		if(can)tmp[cnt++]=1;

		for(int i=n+1;i<2*n;i++){
			int v1=int(C1[i]+0.5);
			int v2=int(C2[i]+0.5);
			if(i-n+1<=n/2){
				int len=(i-n+1)*2;
				int nxp=len-1+n;
				int va1=int(C1[nxp]+0.5);
				int va2=int(C2[nxp]+0.5);
				if(v1==v2&&va1==va2)tmp[cnt++]=i-n+1;
			}
			else{
				if(v1==v2)tmp[cnt++]=i-n+1;
			}

		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++){
			if(i==cnt-1)printf("%d\n",tmp[i]);
			else printf("%d ",tmp[i]);
		}
	}
	return 0;
}