H - Genta Game

Statements

Kojima Genta is one of the best friends of Conan, and the fattest one!

Everyone believes that Genta is just thinking about food. So, he wants to prove the opposite. So, his friends challenged him in a game. Genta's friends will give him a string s of length n, and m update operations. At each update operation, an integer p (1 ≤ p ≤ n) and a lowercase English letter c will be given to Genta, and he is asked to change the pth letter in the string s to the letter c.

Conan explained to Genta that an update operation is said to be beautiful if the string s was a palindrome string after the update operation has been executed.

Genta task is to count the number of beautiful update operations. Genta wants to win in this game no matter what this will cost because his friends promised him that the food will be at their expense throughout the week if he solved the task. Can you help Genta by solving his task?

Input

The first line contains an integer T (1 ≤ T ≤ 50), in which T is the number of test cases.

The first line of each test cases contains two integers n and m (1 ≤ n, m ≤ 105), in which n is the length of the string s and m is the number of update operations. The second line of each test cases contains a string s of length n consisting of lowercase English letters only. Then m lines follow, each line contains an integer p and a lowercase English letter c (1 ≤ p ≤ n), giving the update operations.

The sum of n and m overall test cases does not exceed 7 × 105 for each.

Output

For each test case, print a single line containing the number of beautiful update operations.

Example

Input

1
10 7
abcdefdcba
5 x
6 x
4 d
2 d
3 y
8 y
9 d

Output

3

Note

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar".

In the first test case, the string s will be updated as follow:

abcdefdcba  abcdxfdcba  abcdxxdcba abcdxxdcba  adcdxxdcba  adydxxdcba adydxxdyba  adydxxdyda.

There are 3 beautiful update operations, which are the 2rd, 3th, and 7th operations.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {

        int n,m;
        char st[11000002];
        scanf("%d%d",&n,&m);
        scanf("%s",st);
        st[n]='\0';
        int len=strlen(st);
        int ans=0;
        int i,j;
        for(i=0,j=len-1;j>i; i++,j--)
        {
            if(st[i]!=st[j])
                ans++;

        }
        int u;
        char ch;
        int sum=0;
        for(i=1; i<=m; i++)
        {

            scanf("%d",&u);
            getchar();
            scanf("%c",&ch);
            char c=st[u-1];
            st[u-1]=ch;
            if(st[u-1]==st[len-u]&&c!=st[len-u]&&(u-1)!=(len-u))
                ans--;
            else if(st[u-1]!=st[len-u]&&c==st[len-u])
                ans++;
            if(ans==0)
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
车辆运动学是研究车辆运动规律和性能的学科,涉及到车辆的运动、操控、稳定性等方面。以下是一些关于车辆运动学理论的好书推荐: 1. 《车辆动力学与控制》(Vehicle Dynamics and Control)- Rajesh Rajamani 这本书详细介绍了车辆动力学和控制的基本原理,包括车辆运动学、轮胎力学、悬挂系统、制动系统等内容。适合对车辆运动学有一定了解的读者。 2. 《车辆运动学与动力学》(Vehicle Dynamics and Damping)- Giancarlo Genta 这本书介绍了车辆运动学和动力学的基本原理,包括车辆悬挂系统、轮胎力学、转向系统等内容。书中还包含了一些实例和案例分析,有助于读者更好地理解和应用。 3. 《车辆运动学与控制》(Vehicle Dynamics and Control)- Masato Abe 这本书系统地介绍了车辆运动学和控制的理论和方法,包括车辆运动模型、轮胎力学、悬挂系统、制动系统等内容。书中还包含了一些实例和仿真分析,有助于读者深入理解和应用。 4. 《车辆运动学与动力学》(Vehicle Dynamics and Control)- Reza N. Jazar 这本书综合介绍了车辆运动学和动力学的理论和方法,包括车辆运动模型、轮胎力学、悬挂系统、制动系统等内容。书中还包含了一些实例和案例分析,有助于读者理解和应用。 这些书籍都是关于车辆运动学理论的经典著作,适合对车辆运动学感兴趣或从事相关研究的读者阅读。希望对你有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值