Compound Conversion

3.7

27 votes
Easy
Problem

Jesse and Walter recently got a into a problem. They need to check if a compound can be converted to the other one. A compound is decoded into a binary strings of 0s and 1s. They have 2 binary strings. First string contains characters '0', '1' and '?', whereas second contains '0' and '1' only. As Jesse and Walter are busy cooking meth, they need your help.

For each case, you need to calculate number of steps needed to convert first compound to second. You can perform the following operations:

  1. Change '0' to '1'

  2. Change '?' to '0' or '1'

  3. Swap any two characters

Input:

First Line of the Input contains T, denoting number of test cases. Then for each test case, there are two lines containg 2 strings denoting the compounds.

Output:

For each test case Print minimum number of steps needed to convert 1st compound to the 2nd in seperate lines. If it is not possible, output -1.

Constraints:

1 <= Length of strings <= 100


Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?