Problem: Sasha has two binary strings and of the same length , consisting of the characters 0 and 1.
There is also a computing machine that can perform two types of operations on binary strings and of the same length :
- If 0, then you can assign 1 ().
- If 1, then you can assign 1 ().
Sasha became interested in the following: if we consider the string and the string , what is the maximum number of 1 characters in the string that can be obtained using the computing machine. Since Sasha is very curious but lazy, it is up to you to answer this question for several pairs that interest him.
Input Format: Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the strings and .
The second line of each test case contains a binary string of length , consisting of the characters 0 and 1.
The third line of each test case contains a binary string of length , consisting of the characters 0 and 1.
The fourth line of each test case contains a single integer () — the number of queries.
The -th of the following lines contains two integers and () — the boundaries of the -th pair of substrings that interest Sasha.
It is guaranteed that the sum of over all test cases does not exceed and the sum of over all test cases does not exceed .
Output Format: For each test case, output integers — the answers to all queries.
Note: In the first test case:
- In the first query, 11, so the maximum number of 1 characters is .
- In the second query, 111, so the maximum number of 1 characters is .
In the second test case:
- In the first query, 101 and 110. No operations can be performed, so the maximum number of 1 characters is .
- In the second query, 1010 and 1101. Since 0, we can assign 1. Now 1, so we can assign 1. The string becomes 1110, so the maximum number of 1 characters is .