Compare those strings

 Chef has two strings 

A and B consisting of lowercase alphabets, each of length N. Help Chef in finding the number of indices i (1iN) such that A[iN]<B[iN].

  • S[iN] denotes the suffix of string S starting at index i, i.e. SiSi+1  SN.
  • String S< String T denotes that S is lexicographically smaller than T. If two strings S and T have the same length N, we say that S is lexicographically smaller than T if there exists an index i(1iN) such that S1=T1, S2=T2,,Si1=Ti1 and Si<Ti. For example, "abc" is lexicographically smaller than "acd", "abe", but not smaller than "abc", "aac".

Input Format

  • The first line contains T denoting the number of test cases. Then the test cases follow.
  • The first line of each test case contains N, denoting the length of the strings A and B.
  • The second line of each test case contains the string A.
  • The third line of each test case contains the string B.

Output Format

For each test case, print a single line containing one integer - the number of indices i such that A[iN]<B[iN].

Constraints

  • 1T105
  • 1N106
  • The sum of N over all test cases does not exceed 106

Sample Input 1 

2
2
ab
bb
3
aaa
aab

Sample Output 1 

1
3

Explanation

Test Case 1:

  • For i=1A[12]= "ab", B[12]= "bb" and lexicographically, "ab< "bb".
  • For i=2A[22]= "b", B[22]= "b" and lexicographically, "b= "b".

Test Case 2: For each i{1,2,3}A[i3]<B[i3].

Previous
Next Post »