Masala E

Xotira 256 MB Vaqt 2000 ms
14

Kamron and Binary String (Easy Version)

This is the easy version of the problem. The difference between the versions is that in this version, string tt consists of only '0' and '1'. You can hack only if you solved all versions of this problem.

Kamron has a binary string ss of length nn. Kamron can perform the following operation:

  • Choose two adjacent blocks of ss and swap them.

A block is a maximal substringsubstring∗ of identical characters. Formally, denote s[l,r]s[l,r] as the substring slsl+1sr.s_ls_{l+1}…s_r. A block is s[l,r]s[l,r] satisfying:

  • l=1orslsl1.l=1 or s_l≠s_{l-1}.
  • sl=sl+1==sr.s_l=s_{l+1}=…=s_r.
  • r=norsrsr+1.r=n or s_r≠s_{r+1}.

Adjacent blocks are two blocks s[l1,r1]s[l_1,r_1] and s[l2,r2]s[l_2,r_2] satisfying r1+1=l2r_1+1=l_2.

For example, if s=0001100111s=0001100111, Kamron can choose the two blocks s[4,5]s[4,5] and s[6,7]s[6,7] and swap them, transforming ss into 00000111110000011111.

Given a string t of length n consisting of '0', '1' and '?', Kamron wants to determine the minimum number of operations required to perform such that for any index i(1in)i (1≤i≤n), if ti?t_i≠ '?' then si=tis_i=t_i. If it is impossible, output 1−1.

∗∗A string a is a substring of a string b if a can be obtained from b by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Kiruvchi ma'lumotlar:

Each test contains multiple test cases. The first line contains the number of test cases t(1t104)t (1≤t≤10^4). The description of the test cases follows.

The first line of each test case contains a string s consisting of '0' and '1'.

The second line of each test case contains a string t consisting of '0' and '1'.

It is guaranteed that the lengths of s and tt are the same.

It is guaranteed that the sum of the length of ss over all test cases will not exceed 41054⋅10^5.


Chiquvchi ma'lumotlar:

For each test case, output one integer — the minimum number of operations required. If it is impossible, output −1.


Misollar
# input.txt output.txt
1
6
0001100111
0000011111
010101
111000
0101
0110
0101
1010
011001
001110
0
1
1
3
1
-1
-1
-1
Izoh:

In the first test case, the possible way is shown in the statement.

In the second test case, one possible way could be:

  • Swap blocks [2,2],[3,3][2,2],[3,3], s will become 001101001101.
  • Swap blocks [3,4],[5,5][3,4],[5,5], s will become 000111000111.
  • Swap blocks [1,3],[4,6][1,3],[4,6], s will become 111000111000.