C. Make Them Equal

time limit per test

2 seconds

memory limit per test

256 megabytes

Theofanis has a string s1s2...sn and a character c. He wants to make all characters of the string equal to c using the minimum number of operations.

In one operation he can choose a number x (1≤x≤n) and for every position i, where i is not divisible by x, replace si with c.

Find the minimum number of operations required to make all the characters equal to c and the x-s that he should use in his operations.

Input

The first line contains a single integer t (1≤t≤104) --- the number of test cases.

The first line of each test case contains the integer n (3≤n≤3⋅105) and a lowercase Latin letter c --- the length of the string s and the character the resulting string should consist of.

The second line of each test case contains a string s of lowercase Latin letters --- the initial string.

It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.

Output

For each test case, firstly print one integer m --- the minimum number of operations required to make all the characters equal to c.

Next, print m integers x1,x2,...,xm (1≤xj≤n) --- the x-s that should be used in the order they are given.

It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.

Example

Input

Copy

复制代码
3
4 a
aaaa
4 a
baaa
4 b
bzyx

Output

Copy

复制代码
0
1
2
2 
2 3

Note

Let's describe what happens in the third test case:

  1. x1=2: we choose all positions that are not divisible by 2 and replace them, i. e. bzyx → bzbx;
  2. x2=3: we choose all positions that are not divisible by 3 and replace them, i. e. bzbx → bbbb.

解题说明:此题是一道字符串题,给定一个长度为 n 的字符串 s 和一个字符 c,每次操作可以选一个位置 i(1-indexed),把所有不是 i 的倍数的位置上的字符都变成 c。要求用最少的操作次数使整个字符串都变成 c。找规律能发现,最多只有两次。0 次操作 :如果所有字符已经是 c。1 次操作 :如果存在某个位置 i(i > n/2),使得所有不等于 c 的位置都不是 i 的倍数。由于 i > n/2 时,i 在 [1,n] 内没有其他倍数(2i > n),所以只要 s[i-1] == c 且 i > n/2,选 i 就能一次搞定。2 次操作 :否则选 n-1 和 n。对于 n-1:它的倍数只有 n-1(因为 2(n-1) > n 当 n ≥ 3);对于 n:倍数只有 n。两次操作覆盖了这两个"漏网"位置,其余位置都被第一次或第二次操作覆盖。可以证明 2 次总是足够的。

cpp 复制代码
#include <stdio.h>

int main()
{
    int t;
    long long int n, y, k;
    char c;
    scanf("%d", &t);
    while (t != 0)
    {
        y = 0;
        k = 0;
        --t;
        scanf("%lld", &n);
        char s[n];
        scanf(" %c", &c);
        scanf("%s", s);
        for (long long int i = 0; i < n; ++i)
        {
            if (s[i] == c)
            {
                ++k;
                if (i + 1 >= n / 2 + 1)
                {
                    y = i + 1;
                }
            }
        }
        if (k == n) 
        {
            printf("0\n");
            continue;
        }
        else if (y != 0) 
        {
            printf("1 %lld\n", y);
            continue;
        }
        else 
        {
            printf("2 %lld %lld\n", n - 1, n);
            continue;
        }
    }
    return 0;
}
相关推荐
tryCbest44 分钟前
Python 爬虫扩展篇(二):验证码的检测与人工介入——把“拦路虎”当作信号,而不是要征服的对手
开发语言·爬虫·python
风落青芜3 小时前
排序算法(四):归并排序、计数排序与算法总结
c语言·开发语言·数据结构·算法·排序算法
Resean02233 小时前
讲透Java(14)泛型的本质:类型擦除与桥接方法
java·开发语言
智能收银研究所3 小时前
收银系统选型对比:美团、客如云、拉卡拉、收钱吧各适合什么门店
java·前端·数据库
Zwawa6 小时前
GPS 模块怎么用:NMEA 语句怎么读、度分怎么换算成度、校验和怎么验,以及 GNSS、IMU 和轮子怎么融合出位置
c语言·单片机·嵌入式
滑动变滚动的蜗牛6 小时前
我发布了自己的个人小程序(诉述洞)
前端·ai编程·全栈
ZYH_06017 小时前
Shell 第一阶段笔记:变量、引号与变量截取
前端·chrome·笔记
YIAN8 小时前
流式 TTS 和普通TTS到底有什么区别?一个文档教会你!
前端·websocket·node.js
apcipot_rain8 小时前
C++开发 面试 1Day速通
开发语言·c++·面试