
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains one binary string, ‘P’ denoting the binary representation of the first number.
The following line contains one binary string, ‘Q’, denoting the binary representation of the second number.
For each test case, print a single integer denoting the number of times the while loop will run.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= |P|, |Q| <= 10^5
Sum of all |P| + |Q| overall test cases will not exceed 10^6.
Time Limit: 1 sec
Note that, ‘B’ represents digiti-wise sum and ‘A’ represents carry. For example, let’s say an index ‘i’ of ‘P’ is ‘1’ and that for ‘Q’ is ‘1’, then ‘B[i]’ will store ‘0’ and ‘A[i]’ will store ‘1’ which is the digit-wise sum and carry.
We may interpret the whole process as if we simultaneously started addition in all points and carried excessive bits in all places at the same time. The final answer will be the length of the longest carry chain.
We can get the whole time of the process by some case-work.Notice the following for ‘P[i]’ + ‘Q[i]’ + carry[i].
Thus, the answer to the problem can be obtained by carefully simulating the process. You should also take an extra look at the B = 0 case.
For example, if ‘P’ = 1 and ‘Q’ = 1, after 1st iteration ‘P’ will become 0 and ‘Q’ will become ‘10’. After the second iteration, both ‘P’ and ‘Q’ will become 0, so answer for this will be 2.