#codeforcesP1996C. Sort
Sort
Problem
You are given two strings and of length Then, you are (forced against your will) to answer queries.
For each query, you are given a range bounded by and . In one operation, you can choose an integer and set where is any character you desire. Output the minimum number of operations you must perform such that sorted=sorted. The operations you perform on one query does not affect other queries.
For an arbitrary string , sorteddenotes the substring consisting of characters sorted in lexicographical order.
Input
The first line contains – the number of test cases.
The first line of each test case contains two integers and – the length of both strings and the number of queries.
The following line contains a of length . It is guaranteed a only contains lowercase latin letters.
The following line contains of length It is guaranteed b only contains lowercase latin letters.The following lines contain two integers and – the range of the query.
It is guaranteed the sum of and over all test cases does not exceed .
Output
For each query, output an integer, the minimum number of operations you need to perform in a new line.
Example : in
3
5 3
abcde
edcba
1 5
1 4
3 3
4 2
zzde
azbe
1 3
1 4
6 3
uwuwuw
wuwuwu
2 4
1 3
1 6
Example : out
0
1
0
2
2
1
1
0
Note
For the first query, sorted and sorted, so no operations are necessary.
For the second query, you need to set Then, sorted sorted.
相关
在下列比赛中: