Limits 500ms, 128 MB

A binary string is a string that consists of only the character 00 and 11. For example: 1010,0,111010, 0, 11 are binary strings.

Bob was given a problem to solve by his teacher. The problem is about binary strings. As Bob has recently started learning about strings, he is not quite sure if he can solve the problem. But maybe he can if you give him some hints !!

The problem as follows: You are given two binary string AA and BB. Consider a set S=(i1,i2,...,ik)S = (i_1, i_2,..., i_k) that contains all the indices ii such that A[i]=1A[i] = 1. Similarly, let T=(j1,j2,...,jr)T = (j_1, j_2,..., j_r) that contains all the indices jj such that B[j]=1B[j] = 1. Now you have to find the sum of ij|i - j| for all ii and jj such that ii belongs to SS and jj belongs to TT.

More formally, find the value of iSjTij\sum\limits_{i \in S}^{j \in T} |i - j|

To give hints to Bob, you show him only this value but not the actual solution or how to do it.

For example, let A=101,B=110.A = 101, B = 110. Then, S=(1,3)S = (1, 3) and T=(1,2).T = (1, 2). So the answer is: 11+12+31+32=0+1+2+1=4.|1 - 1| + |1 - 2| + |3 - 1| + |3 - 2| = 0 + 1 + 2 + 1 = 4.

Note that x|x| denotes the absolute value of x.x.

Input

The first line contains an integer TT the number of test cases (1T103)(1 \leq T \leq 10^3).

For each test case, the first line contains an integer nn (1n105)(1 \leq n \leq 10^5) — the size of the binary string AA and BB. The next two line contains the binary string AA and BB respectively.

It is guaranteed that both AA and BB are binary string. It is also guaranteed that the sum of nn over all test cases does not exceed 105.10^5.

Output

For each test case, print the value described above.

Sample

InputOutput
3
2
01
01
3
101
110
6
101010
011011
0
4
24

Submit

Login to submit.

Statistics

70% Solution Ratio
insane_curiousEarliest, Nov '22
HilariaFastest, 0.0s
nusuBotLightest, 4.9 MB
HilariaShortest, 562B
Toph uses cookies. By continuing you agree to our Cookie Policy.