Bits Equalizer

Given S with 0, 1, ? and T with 0 and 1, find the fewest moves (0 to 1, ? to 0 or 1, swap two positions) to turn S into T, or -1.

Medium5GreedyStringMathImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given two strings SS and TT of the same length. SS consists of the characters 0, 1 and ?, and TT consists of 0 and 1 only. Convert SS into TT using as few moves as possible. One move is one of the following:

  1. change a 0 in SS to 1
  2. change a ? in SS to 0 or 1
  3. swap two characters of SS

No move turns a 1 back into a 0.

For example, take S=S = 01??00 and T=T = 001010. Three moves are enough:

  • at the start S=S = 01??00
  • move 1 changes the third character to 1, so S=S = 011?00
  • move 2 changes the fourth character to 0, so S=S = 011000
  • move 3 swaps the second character with the fifth character, so S=S = 001010

Input

The first line holds the number of test cases CC. (1C2001 \le C \le 200)

Each test case is two lines. The first line holds the string SS made of 0, 1 and ?. The second line holds the string TT made of 0 and 1. The two strings have the same length, which is between 1 and 100.

Output

For each test case, print one line in the format Case x: y, where xx is the test case number starting at 1 and yy is the minimum number of moves that turns SS into TT. If no sequence of moves turns SS into TT, print -1 in place of yy.