CF1202A.You Are Given Two Binary Strings...

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

You Are Given Two Binary Strings...

You are given two binary strings xx and yy, which are binary representations of some two integers (let's denote these integers as f(x)f(x) and f(y)f(y)). You can choose any integer k0k \ge 0, calculate the expression sk=f(x)+f(y)2ks_k = f(x) + f(y) \cdot 2^k and write the binary representation of sks_k in reverse order (let's denote it as revkrev_k). For example, let x=1010x = 1010 and y=11y = 11; you've chosen k=1k = 1 and, since 21=1022^1 = 10_2, so sk=10102+112102=100002s_k = 1010_2 + 11_2 \cdot 10_2 = 10000_2 and revk=00001rev_k = 00001.

For given xx and yy, you need to choose such kk that revkrev_k is lexicographically minimal (read notes if you don't know what does "lexicographically" means).

It's guaranteed that, with given constraints, kk exists and is finite.

Input

The first line contains a single integer TT (1T1001 \le T \le 100) — the number of queries.

Next 2T2T lines contain a description of queries: two lines per query. The first line contains one binary string xx, consisting of no more than 10510^5 characters. Each character is either 0 or 1.

The second line contains one binary string yy, consisting of no more than 10510^5 characters. Each character is either 0 or 1.

It's guaranteed, that 1f(y)f(x)1 \le f(y) \le f(x) (where f(x)f(x) is the integer represented by xx, and f(y)f(y) is the integer represented by yy), both representations don't have any leading zeroes, the total length of xx over all queries doesn't exceed 10510^5, and the total length of yy over all queries doesn't exceed 10510^5.

Output

Print TT integers (one per query). For each query print such kk that revkrev_k is lexicographically minimal.

Note

The first query was described in the legend.

In the second query, it's optimal to choose k=3k = 3. The 23=100022^3 = 1000_2 so $s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001$ and rev3=1000001rev_3 = 1000001. For example, if k=0k = 0, then s0=10111s_0 = 10111 and rev0=11101rev_0 = 11101, but rev3=1000001rev_3 = 1000001 is lexicographically smaller than rev0=11101rev_0 = 11101.

In the third query s0=10s_0 = 10 and rev0=01rev_0 = 01. For example, s2=101s_2 = 101 and rev2=101rev_2 = 101. And 0101 is lexicographically smaller than 101101.

The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."

Samples

4
1010
11
10001
110
1
1
1010101010101
11110000
1
3
0
0

在线编程 IDE

建议全屏模式获得最佳体验