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

For given $x$ and $y$, you need to choose such $k$ that $rev_k$ is lexicographically minimal (read notes if you don't know what does "lexicographically" means).

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


-----Input-----

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

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

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

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


-----Output-----

Print $T$ integers (one per query). For each query print such $k$ that $rev_k$ is lexicographically minimal.


-----Example-----
Input
4
1010
11
10001
110
1
1
1010101010101
11110000

Output
1
3
0
0



-----Note-----

The first query was described in the legend.

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

In the third query $s_0 = 10$ and $rev_0 = 01$. For example, $s_2 = 101$ and $rev_2 = 101$. And $01$ is lexicographically smaller than $101$.

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."

Difficulty: EASY
Tags: Bit manipulation

Greedy algorithms
Skill types: Bit manipulation

Greedy algorithms

Starter code:

Solutions:
t = int(input())
output = []
for i in range(t):
	x = input()
	y = input()
	(x, y) = (x[::-1], y[::-1])
	pos_y = y.find('1')
	pos_x = x.find('1', pos_y)
	output.append(str(pos_x - pos_y))
print('\n'.join(output))


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	x = list(reversed(x))
	y = list(reversed(y))
	first_one_in_y = None
	for i in range(len(y)):
		if y[i] == '1':
			first_one_in_y = i
			break
	if first_one_in_y is None:
		print(0)
		continue
	first_one_in_x = None
	for j in range(first_one_in_y, len(x)):
		if x[j] == '1':
			first_one_in_x = j
			break
	if first_one_in_x is None:
		print(0)
	else:
		print(first_one_in_x - first_one_in_y)


def dz(y):
	c = 0
	for x in reversed(y):
		if x == '0':
			c += 1
		else:
			break
	return c

def score(x, y):
	d = dz(y)
	if d == 0:
		return dz(x)
	return dz(x[:-d])
for _ in range(int(input())):
	print(score(input(), input()))


I = input
for i in range(int(I())):
	(x, y) = (I()[::-1], I()[::-1])
	print(x[y.index('1'):].index('1'))


a = int(input())
for _ in range(a):
	(x, y) = (list(input()), list(input()))
	y.reverse()
	x.reverse()
	b = y.index('1')
	c = x.index('1', b)
	print(c - b)
	continue


from sys import stdin, stdout
from itertools import accumulate
T = int(input())
for i in range(T):
	b1 = input()
	b2 = input()
	b1_len = len(b1)
	b2_len = len(b2)
	b1 = b1[::-1]
	b2 = b2[::-1]
	idx = -1
	for j in range(b2_len):
		if b2[j] == '1':
			idx = j
			break
	k = 0
	for j in range(idx, b1_len):
		if b1[j] == '1':
			print(k)
			break
		k += 1


n = int(input())
for i in range(n):
	a = input()
	b = input()
	b = b[::-1]
	ind = b.find('1')
	ans = 0
	for j in range(len(a) - 1 - ind, -1, -1):
		if a[j] == '1':
			print(ans)
			break
		else:
			ans += 1


t = int(input())
for _ in range(t):
	x = list(str(input()))
	y = list(str(input()))
	x.reverse()
	y.reverse()
	for (i, c) in enumerate(y):
		if c == '1':
			for j in range(i, len(x)):
				if x[j] == '1':
					break
			else:
				j = len(x)
			break
	print(j - i)


false = False
true = True
null = None
TEST = false
try:
	import sys
	for arg in sys.argv:
		if arg == 'test':
			print('test mode')
			TEST = True
	pass
except:
	pass

def AddImports(libraryNames):
	for libname in libraryNames:
		if type(libname) == type(tuple()):
			short = libname[1]
			libname = libname[0]
		else:
			short = None
		try:
			lib = __import__(libname)
		except ImportError:
			pass
		else:
			if short:
				globals()[short] = lib
			else:
				globals()[libname] = lib
	return True
libnames = ['functools', 'math', 'collections']
AddImports(libnames)
IntellisenseHint = False
if IntellisenseHint:
	import functools
	import math
	import collections

def it(args, *arg):
	if TEST:
		print(args, *arg)

def floatEqual(a, b):
	diff = math.fabs(a - b)
	if diff < 1e-10:
		return True
	else:
		return diff <= 1e-08 * max(math.fabs(a), math.fabs(b))

def ria():
	return list(map(int, input().strip(' ').split(' ')))

def rs():
	return input().strip('\n')

def create2dArray(x, y, val=False):
	arr = [val] * y
	for yy in range(y):
		if x == 0:
			arr[yy] = []
		else:
			arr[yy] = [val] * x
	return arr
from sys import stdin
input = stdin.readline

def solve():
	T = ria()[0]
	for t in range(T):
		x = rs()
		y = rs()
		last1ofy = y.rindex('1')
		posy = len(y) - last1ofy - 1
		last1ofx = x.rindex('1', 0, len(x) - posy)
		posx = len(x) - last1ofx - 1
		print(posx - posy)
	pass
solve()


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	cnt_0 = 0
	for c in reversed(y):
		if c == '1':
			break
		cnt_0 += 1
	k = 0
	for i in range(len(x) - 1 - cnt_0, -1, -1):
		if x[i] == '1':
			break
		k += 1
	print(k)


n = int(input())
for i in range(n):
	x = input()
	y = input()
	y_1 = len(y) - 1
	yy = 0
	while y[y_1] == '0':
		y_1 -= 1
		yy += 1
	x_1 = len(x) - 1 - yy
	xx = 0
	while x[x_1] == '0':
		x_1 -= 1
		xx += 1
	print(xx)


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	x = input()
	y = input()
	pos_y = y.rfind('1')
	d = len(y) - pos_y - 1
	if d != 0:
		pos_x = x[:-d].rfind('1')
	else:
		pos_x = x.rfind('1')
	pos_x = -len(x) + pos_x
	pos_y = -len(y) + pos_y
	k = pos_y - pos_x
	print(k)


def main(bs1, bs2):
	(a, b) = (list(reversed(bs1)), list(reversed(bs2)))
	b_index = b.index('1')
	a_index = a.index('1')
	while a_index < b_index:
		a_index = a.index('1', a_index + 1)
	return a_index - b_index
n = int(input())
for i in range(n):
	print(main(input(), input()))


t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	(n, m) = (len(s1), len(s2))
	i = s1.rfind('1')
	j = m - s2.rfind('1')
	while n - i < j:
		i = s1.rfind('1', 0, i)
	print(0 if i == -1 else n - i - j)


T = int(input())
for _ in range(T):
	s1 = input()
	s2 = input()
	for (buffer, bit) in enumerate(s2[::-1]):
		if bit == '1':
			break
	for (ans, bit) in enumerate(s1[-1 - buffer::-1]):
		if bit == '1':
			break
	print(ans)


a = int(input())
for i in range(a):
	b = input()
	c = input()
	k = c.rfind('1')
	s = len(c) - k
	lent = 10
	h = b[0:len(b) - s + 1]
	for i in range(len(h) - 1, -1, -1):
		if h[i] == '1':
			p = len(h) - 1
			print(p - i)
			break


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	s = get_string()[::-1]
	t = get_string()[::-1]
	first_index = t.index('1')
	sec_ind = s.index('1')
	if first_index <= sec_ind:
		print(sec_ind - first_index)
	else:
		temp = '0' * first_index + s[first_index:]
		sec_ind = temp.index('1')
		print(sec_ind - first_index)


def answer():
	x = input()[::-1]
	y = input()[::-1]
	len_y = len(y)
	if '1' in y and '1' in x:
		left_pos_y = y.index('1')
		xx1 = x[left_pos_y:]
		xx2 = x[:left_pos_y]
		len_xx1 = len(xx1)
		len_xx2 = len(xx2)
		x_dummy = '0' * left_pos_y + x[left_pos_y:]
		if '1' in x_dummy:
			left_pos_x = x_dummy.index('1')
			out = left_pos_x - left_pos_y
			return out
		else:
			return 0
	else:
		return 0
n = int(input())
for i in range(n):
	out = answer()
	print(out)


t = int(input())
while t:
	x = input()
	y = input()
	c0y = 0
	j = len(y) - 1
	while 1:
		if y[j] == '0':
			c0y += 1
			j -= 1
		else:
			break
	c0x = 0
	j = len(x) - 1
	while 1:
		if x[j] == '0':
			c0x += 1
			j -= 1
		elif x[j] == '1' and c0y > c0x:
			c0x += 1
			j -= 1
		else:
			break
	ans = c0x - c0y
	print(ans)
	t -= 1


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	S = list(input().rstrip())
	T = list(input().rstrip())
	Query.append((S, T))
for (S, T) in Query:
	L = len(T)
	L2 = len(S)
	for i in range(L):
		if T[-i - 1] == '1':
			for j in range(i, L2):
				if S[-j - 1] == '1':
					ans = j - i
					break
			break
	print(ans)


for _ in range(int(input())):
	(a, b, s) = (reversed(input()), reversed(input()), 0)
	while b.__next__() == '0':
		a.__next__()
	while a.__next__() == '0':
		s += 1
	print(s)


n = int(input())
for _ in range(n):
	a = input()[::-1]
	b = input()[::-1]
	x = b.find('1')
	print(a.find('1', x) - x)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	x = str(input())
	y = str(input())
	x = x[::-1]
	y = y[::-1]
	ans = 0
	i = 0
	while y[i] != '1':
		i += 1
	while x[i] != '1':
		ans += 1
		i += 1
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


for _ in range(int(input())):
	a = input()
	b = input()
	b = b[::-1]
	a = a[::-1]
	lol = b.index('1')
	a = a[lol:]
	print(a.index('1'))


for k in range(int(input())):
	a = input()
	b = input()
	if a[-1] == '1':
		if b[-1] == '1':
			print(0)
		else:
			jj = 0
			n = len(b)
			for i in range(0, len(b)):
				if b[n - 1 - i] == '1':
					jj = i
					break
			ii = 0
			n = len(a)
			for i in range(1, len(a)):
				if a[n - 1 - i] == '1':
					ii = i
					if ii >= jj:
						break
			if ii - jj <= 0:
				print(0)
			else:
				print(ii - jj)
	else:
		jj = 0
		n = len(b)
		for i in range(0, len(b)):
			if b[n - 1 - i] == '1':
				jj = i
				break
		ii = 0
		n = len(a)
		for i in range(1, len(a)):
			if a[n - 1 - i] == '1':
				ii = i
				if ii >= jj:
					break
		if ii - jj <= 0:
			print(0)
		else:
			print(ii - jj)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	l = 0
	for i in y[-1::-1]:
		if i == '1':
			break
		l += 1
	j = 0
	for i in range(len(x)):
		if j < l:
			pass
		elif x[-i - 1] == '1':
			ind = i
			break
		j += 1
	print(ind - l)


for _ in range(int(input())):
	a = int(input(), 2)
	b = int(input(), 2)
	j = 0
	while b >> j & 1 == 0:
		j += 1
	i = j
	while a >> i & 1 == 0:
		i += 1
	print(i - j)


t = int(input())
for _ in range(t):
	x = input()[::-1]
	y = input()[::-1]
	t = y.find('1')
	tmp = x[t:].index('1') + t
	print(tmp - t)


T = int(input())
for i in range(T):
	x = input()
	y = input()
	last_1_of_y_pos = 0
	for j in range(-1, -len(y) - 1, -1):
		if y[j] == '1':
			last_1_of_y_pos = j
			break
	for j in range(last_1_of_y_pos, -len(x) - 1, -1):
		if x[j] == '1':
			k = -j + last_1_of_y_pos
			print(k)
			break


q = int(input())
for _ in range(q):
	a = [int(x) for x in list(input())]
	b = [int(x) for x in list(input())]
	a.reverse()
	b.reverse()
	(indexA, indexB) = (0, b.index(1))
	for i in range(indexB, len(a)):
		if a[i] == 1:
			indexA = i
			break
	print(indexA - indexB)


T = int(input())
for i in range(T):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	posY = y.find('1')
	posX = x.find('1', posY)
	print(posX - posY)


for _ in range(int(input().strip())):
	x = input()
	y = input()
	X = len(x)
	Y = len(y)
	for i in range(Y - 1, -1, -1):
		if y[i] == '1':
			break
	for j in range(X - Y + i, -1, -1):
		if x[j] == '1':
			print(X - j - (Y - i))
			break


for _ in range(int(input())):
	has = input()[::-1]
	chk = input()[::-1]
	indx = chk.index('1')
	print(has.index('1', indx) - indx)


import sys

def main():
	n = int(sys.stdin.readline())
	for i in range(n):
		x = sys.stdin.readline().rstrip()
		y = sys.stdin.readline().rstrip()
		x = x[::-1]
		y = y[::-1]
		ypos = y.index('1')
		xpos = x[ypos:].index('1') + ypos
		print(xpos - ypos)
main()


t = int(input())
while t > 0:
	t -= 1
	flag = 0
	a = input()
	a = list(a)
	b = input()
	b = list(b)
	a = a[::-1]
	b = b[::-1]
	p = b.index('1')
	for i in range(len(a)):
		if a[i] == '1' and i - p >= 0:
			print(i - p)
			flag = 1
			break
	if not flag:
		print(0)


import sys, os, io
input = sys.stdin.readline
for _ in range(int(input())):
	a = input().strip()
	b = input().strip()
	m = max(len(a), len(b))
	a = '0' * (m - len(a)) + a
	b = '0' * (m - len(b)) + b
	ao = []
	bo = []
	for i in range(len(a)):
		if a[i] == '1':
			ao.append(i)
	for i in range(len(b)):
		if b[i] == '1':
			bo.append(i)
	while len(ao) and ao[-1] > bo[-1]:
		ao.pop()
	if len(ao) == 0:
		print(0)
	else:
		print(bo[-1] - ao[-1])


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	i = 1
	while y[-i] == '0':
		i += 1
	j = 0
	while x[-i - j] == '0':
		j += 1
	print(j)


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	x = sys.stdin.readline().rstrip()
	y = sys.stdin.readline().rstrip()
	x_one = []
	temp_x = x[::-1]
	for i in range(len(x)):
		if temp_x[i] == '1':
			x_one.append(i)
	temp_y = y[::-1]
	idx = -1
	for i in range(len(y)):
		if temp_y[i] == '1':
			idx = i
			break
	for i in x_one:
		if i >= idx:
			print(i - idx)
			break


for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	posy = y.index('1')
	posx = posy
	while x[posx] != '1':
		posx += 1
	print(posx - posy)


n = int(input())
for i in range(n):
	a = input()[::-1]
	b = input()[::-1]
	for j in range(0, len(b)):
		if b[j] == '1':
			for k in range(j, len(a)):
				if a[k] == '1':
					print(k - j)
					break
			break


t = int(input())
for i in range(t):
	x = input()
	y = input()
	l = y[::-1].index('1')
	r = x[::-1].index('1', l, len(x))
	print(r - l)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
for _ in range(ri(1)):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	ans = 0
	i = 0
	j = 0
	while i < len(a):
		if a[i] == '0' and b[j] == '1':
			ans += 1
			i += 1
		if a[i] == '0' and b[j] == '0':
			i += 1
			j += 1
		if a[i] == '1' and b[j] == '0':
			i += 1
			j += 1
		if a[i] == '1' and b[j] == '1':
			break
	print(ans)


for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	i = 0
	while y[i] != '1':
		i += 1
	b = i
	while x[i] != '1':
		i += 1
	a = i
	print(a - b)


t = int(input())
while t:
	t += -1
	x = input()
	y = input()
	i2 = 0
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '1':
			break
		i2 -= -1
	i1 = 0
	for i in range(len(x) - i2 - 1, -1, -1):
		if x[i] == '1':
			i1 = i
			break
	print(len(x) - 1 - i2 - i1)


res = []
for TT in range(1, int(input()) + 1):
	(a, b) = (input()[::-1], input()[::-1])
	i = b.index('1')
	j = a[i:].index('1')
	res.append(j)
print(*res, sep='\n')


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
for _ in range(int(input())):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	posb = b.find('1')
	posa = a.find('1', posb)
	print(posa - posb)


t = int(input())
c = 10 ** 5
de = c * '1'
for q in range(t):
	y = input()
	x = input()
	b = 0
	for i in range(1, len(x) + 1):
		if x[-i] == '1':
			b = i
			break
	e = 0
	for i in range(b, len(y) + 1):
		if y[-i] == '1':
			e = i
			break
	if e != 0:
		print(e - b)
	else:
		print(0)


from sys import stdin
read = stdin.readline
T = int(read())
for t in range(T):
	x = read()
	y = read()
	for (i, c) in enumerate(reversed(y)):
		if c == '1':
			break
	for j in range(i + 1, len(x) + 1):
		if x[-j] == '1':
			print(j - i - 1)
			break


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	for i in range(get()):
		test()

def test():
	x = input()
	y = input()
	(y1, y2) = (0, 0)
	for i in range(len(y)):
		if y[len(y) - i - 1] == '1':
			y1 = i
			break
	for i in range(y1, len(x)):
		if x[len(x) - i - 1] == '1':
			y2 = i
			break
	print(y2 - y1)
main()


for i in range(int(input())):
	x = input()
	y = input()
	idx = 0
	for e in range(len(x)):
		if x[e] == '1':
			idx = e
	idx = len(x) - idx
	idy = 0
	for e in range(len(y)):
		if y[e] == '1':
			idy = e
	idy = len(y) - idy
	if idx - idy == 0:
		print(0)
	elif idx > idy:
		print(idx - idy)
	else:
		idx = 0
		for e in range(len(x)):
			if x[e] == '1':
				if len(x) - e >= idy:
					idx = len(x) - e
		print(idx - idy)


t = int(input())
for i in range(t):
	x = input().rstrip()
	y = input().rstrip()
	lastone = 0
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '1':
			break
		lastone += 1
	j = 0
	for i in range(len(x) - 1, -1, -1):
		if x[i] == '1' and j >= lastone:
			break
		j += 1
	print(j - lastone)


for _ in range(int(input())):
	(a, b) = (input(), input())
	x = b[::-1].index('1')
	y = a[::-1].index('1', x)
	print(y - x)


from sys import setcheckinterval, stdin
setcheckinterval(1000)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
for _ in range(iin()):
	a = input()
	b = input()
	n1 = len(a)
	n2 = len(b)
	(i, j) = (n1 - 1, n2 - 1)
	k = 0
	while i >= 0 and j >= 0:
		if a[i] == '1' and b[j] == '1':
			break
		elif a[i] == '1' and b[j] == '0':
			i -= 1
			j -= 1
		elif a[i] == '0' and b[j] == '1':
			k += 1
			i -= 1
		else:
			i -= 1
			j -= 1
	print(k)


from math import *
import sys
MOD = int(1000000000.0) + 7

def nextInt():
	return int(input())

def nextInts():
	return list(map(int, input().split()))

def YN(x):
	return 'YES' if x else 'NO'

def solve():
	x = input()
	y = input()
	ind = 0
	ans = 0
	while y[len(y) - 1 - ind] == '0':
		ind += 1
	while x[len(x) - 1 - ind] == '0':
		ind += 1
		ans += 1
	return ans
t = nextInt()
for i in range(t):
	print(solve())


for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	i = y.find('1')
	print(x.find('1', i) - i)


for _ in [0] * int(input()):
	print(input()[::-1][input()[::-1].find('1'):].find('1'))


for _ in range(int(input())):
	(x, y) = (input(), input())
	i = y[::-1].index('1')
	rx = x[::-1]
	for j in range(i, len(x)):
		if rx[j] == '1':
			break
	print(j - i)


import sys
import math
input = sys.stdin.readline
t = int(input())
for i in range(t):
	x = input()
	y = input()
	if x[-1] == '1' and y[-1] == '1':
		print(0)
	else:
		x = x[::-1]
		y = y[::-1]
		y1 = y.index('1')
		x1 = x[y1:].index('1')
		print(x1)


t = int(input())
while t:
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	posy = y.index('1')
	posx = x.index('1', posy)
	print(posx - posy)
	t = t - 1


import sys
for t in range(int(input())):
	(a, b) = (str(input()), str(input()))
	j = len(a) - b[::-1].index('1')
	i = a[:j][::-1].index('1')
	print(i)


for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	py = y.find('1')
	px = x.find('1', py)
	print(px - py)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	r = y.rfind('1')
	if r < 0:
		print(0)
	else:
		l = len(x) - len(y) + r
		print(l - x[:l + 1].rfind('1'))


n = int(input())
for i in range(n):
	s = input().rstrip()
	t = input().rstrip()
	ans = 0
	place = -1
	for (i, t_cs) in enumerate(t[::-1]):
		if t_cs == '0' and place == -1:
			continue
		if t_cs == '1' and place == -1:
			place = i
			break
	for s_cs in s[::-1][place:]:
		if s_cs == '0':
			ans += 1
			continue
		else:
			break
	print(ans)


q = int(input())
for _ in range(q):
	x = list(input())
	y = list(input())
	i = 0
	while y[-i - 1] == '0':
		i += 1
	j = i
	while x[-i - 1] == '0':
		i += 1
	print(i - j)


T = int(input())
while T:
	x = input()
	y = input()
	for j in range(len(y)):
		if y[len(y) - 1 - j] == '1':
			break
	count = 0
	for i in range(j, len(x)):
		if x[len(x) - 1 - i] == '1':
			break
		else:
			count += 1
	print(count)
	T -= 1


import sys
import math as mt
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	x = input()
	y = input()
	ind = 0
	ind1 = 0
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '1':
			break
		ind += 1
	ch = 0
	ch1 = -1
	for i in range(len(x) - 1 - ind, -1, -1):
		if x[i] == '1':
			ch1 = 1
			break
		ch += 1
	if ind == len(y):
		print(0)
	elif ch1 == -1:
		print(0)
	else:
		print(ch)


import sys
input = sys.stdin.readline
T = int(input())
x = []
y = []
for i in range(2 * T):
	if i % 2 == 0:
		x.append(input())
	else:
		y.append(input())
for i in range(T):
	n = len(y[i])
	for j in range(n):
		if y[i][n - j - 1] == '1':
			break
	n = len(x[i])
	for k in range(j, n):
		if x[i][n - k - 1] == '1':
			break
	print(k - j)


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	x2 = x[0:len(x) - (len(y) - y.rfind('1') - 1)]
	print(len(x2) - x2.rfind('1') - 1)


t = int(input().strip())
for i in range(t):
	x = input().strip()[-1::-1]
	y = input().strip()[-1::-1]
	ans = 0
	x_one = 0
	y_one = 0
	for (index, i) in enumerate(x):
		if i == '1':
			x_one = index
			break
	for (index, i) in enumerate(y):
		if i == '1':
			y_one = index
			if x_one < index:
				for j in range(index, len(x)):
					if x[j] == '1':
						x_one = j
						break
			break
	print(x_one - y_one if x_one > y_one else y_one - x_one)


def read_int():
	return int(input())
t = read_int()
for case_num in range(t):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	ans = 0
	l = 0
	while b[l] == '0':
		l += 1
	r = 0
	while a[r] == '0' or r < l:
		r += 1
	print(0 if l >= r else r - l)


t = int(input())
for T in range(t):
	x = input()
	y = input()
	x = ''.join(reversed(x))
	y = ''.join(reversed(y))
	y = y.index('1')
	x = x[y:].index('1')
	print(x)


def find_min_k(x, y):
	cnt = 0
	p = len(y) - 1
	while y[p] == '0':
		p -= 1
		cnt += 1
	p = len(x) - cnt - 1
	ans = 0
	while x[p] == '0':
		p -= 1
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	x = input().strip()
	y = input().strip()
	print(find_min_k(x, y))


t = int(input())
for _ in range(t):
	x = int(input(), 2)
	y = int(input(), 2)
	if x % 2 == 1 and y % 2 == 1:
		print(0)
	else:
		k = 0
		if y % 2 == 1 and x % 2 == 0:
			k += 1
			y = y * 2
		while x != 1:
			if x % 2 == 1 and y % 2 == 1:
				break
			x = x // 2
			y = y // 2
			if y % 2 == 1 and x % 2 == 0:
				k += 1
				y = y * 2
		print(k)


n = int(input())
for i in range(n):
	a = input()
	b = input()
	k = b[::-1].index('1')
	a = a[::-1]
	p = a[k:].index('1')
	print(p)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
DEBUG = 0

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)
for _ in range(iread()):
	x = read()
	y = read()
	if x[-1] == y[-1] and x[-1] == '1':
		print(0)
	else:
		start = len(y) - y.rfind('1') - 1
		debug('.', x[:len(x) - start], len(x[:len(x) - start]) - x.rfind('1', 0, len(x) - start) - 1)
		print(len(x[:len(x) - start]) - x.rfind('1', 0, len(x) - start) - 1)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	b = a = 0
	for i in range(-1, -len(y) - 1, -1):
		if y[i] == '1':
			b = -i
			break
	for i in range(-b, -len(x) - 1, -1):
		if x[i] == '1':
			a = -i
			break
	print(max(0, a - b))


import sys
from collections import deque
IS_LOCAL = False

def read_one(dtype=int):
	return dtype(input())

def read_multiple(f, dtype=int):
	return f(map(dtype, input().split()))

def swap(x, y):
	return (y, x)

def solve(xs, ys):
	l = 0
	for (i, x) in enumerate(ys[::-1]):
		if x == '1':
			l = i
			break
	k = 0
	for (i, x) in enumerate(xs[::-1]):
		if i < l:
			continue
		if x == '1':
			k = i
			break
	print(k - l)

def main():
	T = 4
	xs = ['1010', '10001', '1', '1010101010101']
	ys = ['11', '110', '1', '11110000']
	if not IS_LOCAL:
		T = read_one(int)
		for _ in range(T):
			x = input()
			y = input()
			solve(x, y)
	else:
		for (x, y) in zip(xs, ys):
			solve(x, y)
if len(sys.argv) > 1 and sys.argv[1] == 'True':
	IS_LOCAL = True
main()


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	s1 = s1[::-1]
	s2 = s2[::-1]
	if len(s1) >= len(s2):
		s2.zfill(len(s1))
	else:
		s1.zfill(len(s2))
	posy = 0
	for i in range(len(s2)):
		if s2[i] == '1':
			posy = i + 1
			break
	posx = 0
	for i in range(len(s1)):
		if s1[i] == '1' and i + 1 >= posy:
			posx = i + 1
			break
	print(posx - posy)


def solve():
	x = input()
	y = input().rjust(len(x), '0')
	j = y.rfind('1')
	i = x.rfind('1', 0, j + 1)
	print(j - i)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	i = 0
	while i < len(y):
		if y[i] == '1':
			break
		i += 1
	ans = 0
	while i < len(x):
		if x[i] == '1':
			break
		ans += 1
		i += 1
	print(ans)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	a = a[::-1]
	r1 = b[::-1].index('1')
	r2 = a[r1:].index('1')
	print(r2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	s = ri()
	t = ri()
	(pos1, pos2) = (-1, -1)
	for i in range(len(t) - 1, -1, -1):
		if t[i] == '1':
			pos2 = i
			break
	for i in range(len(s) - (len(t) - pos2), -1, -1):
		if s[i] == '1':
			pos1 = i
			break
	if pos2 == -1:
		print(0)
	elif pos1 == -1:
		print(len(s) - len(t))
	else:
		print(len(s) - pos1 - (len(t) - pos2))


t = int(input().strip())
for i in range(t):
	x = input().strip()
	y = input().strip()
	lx = len(x) - 1
	ly = len(y) - 1
	for j in range(0, len(y)):
		if y[ly - j] == '1':
			c1 = j
			break
	a = lx - c1
	c2 = 0
	for j in range(a, -1, -1):
		if x[j] == '1':
			c2 = a - j
			break
	print(c2)


t = int(input())
for i in range(0, t):
	s1 = input()[::-1]
	s2 = input()[::-1]
	print(s1.find('1', s2.find('1')) - s2.find('1'))


import sys
from collections import deque, Counter, OrderedDict, defaultdict
for _ in range(int(input())):
	x = str(input())
	y = str(input())
	idx = -1
	x = x[::-1]
	y = y[::-1]
	(p1, p2) = (0, 0)
	for i in range(len(y)):
		if y[i] == '1':
			p1 = i + 1
			break
	for i in range(len(x)):
		if x[i] == '1' and i + 1 >= p1:
			p2 = i + 1
			break
	print(p2 - p1)


t = input()
t = int(t)
for i in range(t):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	posy = y.index('1')
	posx = x.index('1', posy)
	print(posx - posy)


for _ in range(int(input())):
	a = input()
	b = input()
	firstOccInB = -1
	cnt = 0
	for i in b[::-1]:
		if i == '1':
			firstOccInB = cnt
			break
		cnt += 1
	firstOccInA = -1
	cnt = 0
	for i in a[::-1]:
		if i == '1':
			firstOccInA = cnt
		if firstOccInA >= firstOccInB:
			break
		cnt += 1
	else:
		print(0)
		continue
	print(firstOccInA - firstOccInB)


for i in range(int(input())):
	s1 = input()
	s2 = input()
	a = 1
	for j in range(1, len(s2) + 1):
		if s2[-j] == '1':
			break
		else:
			a += 1
	for j in range(a, len(s1) + 1):
		if s1[-j] == '1':
			print(j - a)
			break


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
for _ in range(int(input())):
	s = list(input())
	t = list(input())
	ct = 0
	while t and t[-1] == '0':
		ct += 1
		t.pop()
	cs = 0
	while s and s[-1] == '0':
		cs += 1
		s.pop()
	if cs >= ct:
		print(cs - ct)
	else:
		ct -= cs
		while ct:
			if not s:
				break
			s.pop()
			ct -= 1
		ans = 0
		while s and s[-1] == '0':
			ans += 1
			s.pop()
		print(ans)


for i in range(int(input())):
	s = input()
	t = input()
	if t == s:
		print(0)
		continue
	if s[-1] == t[-1] == '1':
		print(0)
		continue
	ls = len(s)
	lt = len(t)
	con = 0
	res = 0
	for i in range(lt - 1, -1, -1):
		if t[i] == '1':
			for j in range(ls - con - 1, -1, -1):
				if s[j] == '1':
					break
				res += 1
			break
		con += 1
	print(res)


def foo():
	x = input()
	y = input()
	y = y[::-1]
	y_st = -1
	for i in range(len(y)):
		if y[i] == '1':
			y_st = i
			break
	x = x[::-1]
	for i in range(len(x)):
		if x[i] == '1' and i >= y_st:
			print(i - y_st)
			return
	print('WTF')
for _ in range(int(input())):
	foo()


import os
import sys
from io import BytesIO, IOBase

def main():
	import bisect
	import math
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7
	Max = 10 ** 6
	primes = []
	prime = [True for i in range(Max + 1)]
	p = 2
	while p * p <= Max + 1:
		if prime[p] == True:
			for i in range(p * p, Max + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, Max + 1):
		if prime[p]:
			primes.append(p)

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

	def ncr(n, r):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % mod
			den = den * (i + 1) % mod
		return num * pow(den, mod - 2, mod) % mod

	def solve(x, y):
		arr_x = list(str(x))
		arr_y = list(str(y))
		one_y = 0
		for j in range(len(arr_y) - 1, -1, -1):
			if arr_y[j] == '1':
				one_y = len(arr_y) - 1 - j
				break
		k = 0
		for j in range(len(arr_x) - one_y - 1, -1, -1):
			if arr_x[j] == '1':
				break
			k += 1
		return k
		pass
	t = int(input())
	ans = []
	for _ in range(t):
		x = int(input())
		y = int(input())
		ans.append(solve(x, y))
	for j in range(len(ans)):
		print(ans[j])
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
sys.setrecursionlimit(10 ** 6)

def SI():
	return input().split()

def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
YN = ['Yes', 'No']
YNeos = 'YNeos'
GYN = ['Yes', 'trumpet']
mo = 10 ** 9 + 7
imp = 'IMPOSSIBLE'
t = I()
for _ in range(t):
	x = [int(i) for i in input()]
	y = [int(i) for i in input()]
	for i in range(len(y)):
		if y[-i - 1] == 1:
			yi = i
			break
	xi = 10 * 10
	for i in range(len(x) - yi):
		if x[-yi - i - 1] == 1:
			xi = i
			break
	print(xi)


import time
T = int(input())
for _ in range(0, T):
	k = 0
	x = input()[::-1]
	y = input()[::-1]
	try:
		yy = y.index('1')
	except ValueError:
		yy = 0
	k += yy
	x = x[yy:]
	xx = x.index('1')
	k += xx - yy
	print(k)


t = int(input())
for _ in range(t):
	a = input().strip()
	a = a[::-1]
	b = input().strip()
	b = b[::-1]
	indexy = b.find('1')
	indexx = a.find('1', indexy)
	print(indexx - indexy)


t = int(input())
for i in range(t):
	x = input()
	y = input()
	lx = len(x)
	ly = len(y)
	x0i = lx - x.rfind('1') - 1
	y0i = ly - y.rfind('1') - 1
	if y0i >= lx:
		print(0)
	else:
		while x0i < y0i:
			x0i = lx - x.rfind('1', 0, lx - x0i - 1) - 1
		print(x0i - y0i)


for _ in range(int(input())):
	a = input()[::-1]
	n = len(a)
	b = input()[::-1]
	m = len(b)
	r1 = b.find('1')
	r2 = a[r1:].find('1') + r1
	print(r2 - r1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	a = input()
	b = input()
	b = '0' * (len(a) - len(b)) + b
	j = len(b) - 1
	l = len(a)
	while j >= 0 and b[j] != '1':
		j -= 1
		l -= 1
	a = a[:l]
	if j == -1:
		print(0)
	else:
		print(l - a.rindex('1') - 1)


t = int(input())
for i in range(t):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	for i in range(0, len(y)):
		if y[i] is '1':
			index = i
			break
	for i in range(index, len(x)):
		if x[i] is '1':
			index1 = i
			break
	print(index1 - index)


q = int(input())
for t in range(q):
	x = input()
	y = input()
	a = [i for i in x][::-1]
	b = [i for i in y][::-1]
	i = 0
	j = 0
	pos = -1
	while i < len(a) and j < len(b):
		while i < len(a) and a[i] != '1':
			i += 1
		while j < len(b) and b[j] != '1':
			j += 1
		if i >= j:
			pos = i - j
			break
		else:
			i += 1
	print(pos)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	ind = 0
	ind2 = 0
	for k in range(len(y)):
		i = len(y) - 1 - k
		if y[i] == '1':
			ind2 = k
			break
	for k in range(ind2, len(x)):
		i = len(x) - 1 - k
		if x[i] == '1':
			ind = k
			break
	print(max(0, ind - ind2))


T = int(input())
for _ in range(T):
	x = input()[::-1]
	y = input()[::-1]
	yi = y.index('1')
	xi = x.index('1', yi)
	print(xi - yi)


def main():
	t = int(input())
	for test in range(t):
		x = tuple(map(int, input()))
		y = tuple(map(int, input()))
		i = 0
		while y[-i - 1] == 0:
			i += 1
		j = i
		while x[-j - 1] == 0:
			j += 1
		k = j - i
		print(k)
main()


j = input
for i in range(int(j())):
	(f, s) = (j(), j())
	print(f[:len(f) - s[::-1].index('1')][::-1].index('1'))


def trailing_zeros(str_val):
	res = 0
	for ch in reversed(str_val):
		if ch == '0':
			res += 1
		else:
			break
	return res

def solve(x, y):
	if len(x) == 0 or len(y) == 0:
		return 0
	if x[-1] == '1' and y[-1] == '1':
		return 0
	elif x[-1] == '1' and y[-1] == '0':
		return solve(x[:-1], y[:-1])
	else:
		trailing_zeros_x = trailing_zeros(x)
		trailing_zeros_y = trailing_zeros(y)
		if trailing_zeros_x >= trailing_zeros_y:
			return trailing_zeros_x - trailing_zeros_y
		else:
			return solve(x[:-trailing_zeros_y], y[:-trailing_zeros_y])
T = int(input())
for i in range(T):
	x = input()
	y = input()
	print(solve(x, y))


T = int(input())
for _ in range(T):
	x = input()[::-1]
	y = input()[::-1]
	start = y.index('1')
	offset = x[start:].index('1')
	print(offset)


def query(x, y):
	y1 = y.find('1')
	x1 = x.find('1', y1)
	return x1 - y1
T = int(input())
for i in range(T):
	x = input()[::-1]
	y = input()[::-1]
	print(query(x, y))


t = int(input())
for i in range(t):
	x = input()[::-1]
	y = input()[::-1]
	a = y.index('1')
	b = x.index('1', a)
	print(b - a)


t = int(input())
b = []
for m in range(t):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	ctrl = 0
	for i in range(len(y)):
		if y[i] == '1':
			ctrl = i
			break
	k = 0
	for i in range(ctrl, len(x)):
		if x[i] == '1':
			break
		else:
			k += 1
	b.append(k)
for i in b:
	print(i)


def solve(x, y):
	s = 0
	while y[s] != '1':
		s += 1
	i = s
	while i < len(x) and x[i] != '1':
		i += 1
	return i - s
t = int(input())
for tt in range(t):
	x = input()
	x = x[::-1]
	y = input()
	y = y[::-1]
	print(solve(x, y))


n = int(input())
for i in range(n):
	x = list(reversed(input()))
	y = list(reversed(input()))
	posy = y.index('1')
	posx = x.index('1', posy)
	print(posx - posy)


T = int(input())
for i in range(T):
	x = str(input())
	y = str(input())
	x = x[::-1]
	y = y[::-1]
	y_index = y.find('1')
	x_index = x.find('1', y_index)
	print(x_index - y_index)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	y = b.index('1')
	x = a.index('1', y)
	print(x - y)


for _ in range(int(input())):
	x = input()
	y = input()
	p = len(y) - y.rfind('1') - 1
	k = len(x) - x.rfind('1', 0, len(x) - p) - 1 - p
	print(k)


n = int(input())
for i in range(n):
	t1 = input()
	t2 = input()
	k2 = t2[::-1].index('1')
	r = t1[::-1]
	k1 = r[k2:].index('1')
	print(k1)


T = int(input())
for t in range(T):
	x = input()
	y = input()
	for i in range(1, len(y) + 1):
		if y[-i] == '1':
			y_one = i
			break
	for i in range(y_one, len(x) + 1):
		if x[-i] == '1':
			x_one = i
			break
	ans = max(0, x_one - y_one)
	print(ans)


t = int(input())
for j in range(t):
	x = list(input())
	y = list(input())
	x.reverse()
	y.reverse()
	cx = []
	cy = []
	for i in range(len(x)):
		if x[i] == '1':
			cx.append(i)
	for i in range(len(y)):
		if y[i] == '1':
			cy.append(i)
	for i in range(len(cx)):
		if cx[i] >= cy[0]:
			print(cx[i] - cy[0])
			break


T = int(input())
for i in range(T):
	x = input()
	y = input()
	if y == '0':
		print(0)
		continue
	cnt = len(y) - 1 - y.rfind('1')
	print(len(x) - cnt - 1 - x[:len(x) - cnt].rfind('1'))


t = int(input())
for num in range(t):
	x = str(input())
	y = str(input())
	k = 1
	lx = len(x)
	ly = len(y)
	for i in range(ly - 1, -1, -1):
		if y[i] == '1':
			break
		k += 1
	ans = 0
	for j in range(lx - k, -1, -1):
		if x[j] == '1':
			break
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	s1 = input()[::-1]
	s2 = input()[::-1]
	(count1, count2) = (0, 0)
	for i in range(len(s2)):
		if s2[i] == '1':
			count1 = i
			break
	for i in range(count1, len(s1)):
		if s1[i] == '1':
			count2 = i
			break
	print(max(count2 - count1, 0))


for _ in range(int(input())):
	ans = 0
	s1 = list(input())
	s2 = list(input())
	n1 = len(s1)
	n2 = len(s2)
	cou = 0
	ans = 0
	if n1 < n2:
		s1 = ['0'] * (n2 - n1) + s1
	else:
		s2 = ['0'] * (n1 - n2) + s2
	n = max(n1, n2) - 1
	while n >= 0:
		if s2[n] == '1':
			p = n
			while n >= 0:
				if s1[n] == '1':
					ans = p - n
					cou = 1
					break
				n -= 1
		if cou:
			break
		n -= 1
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	x = input().strip()
	y = input().strip()
	m = len(x)
	n = len(y)
	c = 1
	while True:
		if y[n - c] == '1':
			break
		else:
			c += 1
	j = m - c
	k = 0
	while j >= 0:
		if x[j] == '1':
			print(k)
			break
		else:
			j -= 1
			k += 1


for _ in range(int(input())):
	x = input()
	x = x[::-1]
	y = input()
	y = y[::-1]
	c = 0
	for i in range(len(y)):
		if y[i] == '1':
			c = i
			break
	for i in range(len(x)):
		if x[i] == '1' and i >= c:
			print(i - c)
			break


t = int(input())
for i in range(t):
	x = input()[::-1]
	y = input()[::-1]
	xd = int(x, 2)
	yd = int(y, 2)
	indy = y.index('1')
	indx = indy
	for i in range(indy, len(x)):
		if x[i] == '1':
			indx = i
			break
	print(indx - indy)


def main():
	for _ in range(int(input())):
		x = input()[::-1]
		y = input()[::-1]
		pos_y = y.find('1')
		pos_x = x.find('1', pos_y)
		print(pos_x - pos_y)
main()


for t in range(int(input())):
	s = input()
	c = input()
	ls = len(s)
	lc = len(c)
	for i in range(lc - 1, -1, -1):
		if c[i] == '1':
			break
	ans = 0
	for j in range(ls - (lc - i), -1, -1):
		if s[j] == '1':
			break
		ans += 1
	print(ans)


a = int(input())
for i in range(a):
	b = input()
	c = input()
	k = c.rfind('1')
	s = len(c) - k
	l = 0
	h = b[0:len(b) - s + 1]
	for i in range(len(h) - 1, -1, -1):
		if h[i] == '1':
			l = len(h) - i - 1
			break
	print(l)


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : map(int, rd().strip().split())
T = int(input())
while T:
	x = str(rd())
	y = str(rd())
	x = x[::-1]
	y = y[::-1]
	cnty = 0
	for j in y:
		if j == '1':
			break
		cnty += 1
	cntx = cnty
	for i in range(cnty, len(x)):
		if x[i] == '1':
			break
		cntx += 1
	print(cntx - cnty)
	T -= 1


for t in range(int(input())):
	(a, b) = (input(), input())
	j = len(a) - b[::-1].index('1')
	i = a[:j][::-1].index('1')
	print(i)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	x = sys.stdin.readline().rstrip()
	y = sys.stdin.readline().rstrip()
	(x, y) = (x[::-1], y[::-1])
	pos_y = y.find('1')
	pos_x = x.find('1', pos_y)
	print(pos_x - pos_y)


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	p = -1
	for i in range(len(y)):
		if y[i] == '1':
			p = i
			break
	q = -1
	for i in range(len(x)):
		if x[i] == '1' and i >= p:
			q = i
			break
	ans = q - p
	print(ans)


t = int(input())
for j in range(t):
	l = input()
	l2 = input()
	x1 = 0
	x2 = 0
	for i in range(len(l2)):
		if l2[i] == '1':
			x2 = i
	x2 += len(l) - len(l2)
	for i in range(len(l)):
		if l[i] == '1' and i <= x2:
			x1 = i
	print(x2 - x1)


import sys

def find(s, ch):
	return [len(s) - i - 1 for (i, ltr) in enumerate(s) if ltr == ch]
t_max = int(input())
for t in range(0, t_max):
	x = input()
	y = input()
	pos_list_x = find(x, '1')
	y_last_pos = len(y) - y.rfind('1') - 1
	min_k = sys.maxsize
	for pos in pos_list_x:
		if pos - y_last_pos >= 0:
			min_k = min(min_k, pos - y_last_pos)
	print(min_k)


for _ in range(int(input())):
	x = input()
	y = input()
	sh = len(y) - y.rfind('1')
	cnt = 0
	for i in range(len(x) - sh, -1, -1):
		if x[i] == '1':
			break
		else:
			cnt += 1
	print(cnt)


t = int(input())
for l in range(t):
	a = str(input())
	b = str(input())
	a = a[::-1]
	b = b[::-1]
	s1 = -1
	for i in range(len(b)):
		if b[i] == '1':
			s1 = i
			break
	if s1 == -1:
		print(0)
	else:
		ans = 0
		for j in range(len(a)):
			if a[j] == '1' and j >= i:
				ans = j - i
				break
		print(ans)


t = int(input())
for alsgjsdkgljd in range(t):
	a = input()
	b = input()
	p = b[::-1].find('1') + 1
	coun = 0
	while a[-p] != '1':
		p = p + 1
		coun = coun + 1
	print(coun)


for _ in range(int(input())):
	s = input()
	l = input()
	l = abs(len(s) - len(l)) * '0' + l
	i = l.rfind('1')
	for y in range(i, -1, -1):
		if s[y] == '1':
			break
	print(abs(i - y))


T = input()
for _ in [0] * int(T):
	X = input()
	Y = input()
	Y_index = ~Y[::-1].find('1')
	X_index = X[Y_index::-1].find('1')
	print(X_index)


def search(arr, key):
	(l, r, i) = (0, len(arr) - 1, 0)
	while l != r:
		mid = (l + r) // 2 + i % 2
for q in range(int(input())):
	(s1, s2) = (input(), input())
	t = 0
	for i in range(len(s2)):
		if s2[len(s2) - i - 1] == '1':
			break
		t += 1
	s1 = s1[0:len(s1) - t]
	t = 0
	for i in range(len(s1)):
		if s1[len(s1) - i - 1] == '1':
			break
		t += 1
	print(t)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	c = 0
	for i in range(len(b)):
		if b[len(b) - i - 1] == '1':
			c = i
			break
	d = 0
	for i in range(len(a)):
		if a[len(a) - i - 1] == '1' and i >= c:
			d = i
			break
	print(d - c)


T = int(input())
t = 0
while t < T:
	x = input()
	y = input()
	lx = len(x)
	ly = len(y)
	x = x[::-1]
	y = y[::-1]
	i = 0
	idx = 0
	while i < ly:
		if y[i] == '1':
			idx = i
			break
		i += 1
	i = idx
	k = 0
	while i < lx:
		if x[i] == '1':
			break
		k += 1
		i += 1
	print(k)
	t += 1


T = int(input())
for _ in range(T):
	a = input()[::-1]
	a = a[input()[::-1].index('1'):]
	print(a.index('1') if a else 0)


t = int(input())
for x in range(t):
	a = input()
	b = input()
	i_a = len(a) - 1 - a.rfind('1')
	indices = []
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '1':
			indices.append(len(a) - 1 - i)
	i_b = len(b) - 1 - b.rfind('1')
	res = 0
	while i_b not in indices:
		res += 1
		i_b += 1
	print(res)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
q = ii()
for i in range(q):
	a = input()
	b = input()
	s = 0
	for i in range(len(b)):
		if b[len(b) - 1 - i] == '1':
			s = i
			break
	for i in range(s, len(a)):
		if a[len(a) - 1 - i] == '1':
			print(i - s)
			break


for _ in range(int(input())):
	(s, t) = (input(), input())
	w = s[:t.rfind('1') + len(s) - len(t) + 1]
	print(len(w) - w.rfind('1') - 1)


import sys
input = lambda : sys.stdin.readline().strip()
from math import sqrt
T = int(input())
for i in range(T):
	s1 = input()
	s2 = input()
	for i in range(len(s2) - 1, -1, -1):
		if s2[i] == '1':
			break
	cur = len(s2) - i - 1
	for i in range(len(s1) - 1, -1, -1):
		if s1[i] == '1' and len(s1) - i - 1 >= cur:
			break
	print(len(s1) - i - 1 - cur)


T = int(input())

def find_left(s):
	for (cnt, c) in enumerate(reversed(s)):
		if c != '0':
			return cnt

def find_right(s, x):
	for (cnt, c) in enumerate(reversed(s)):
		if c != '0' and cnt >= x:
			return cnt
for _ in range(T):
	a = input()
	b = input()
	b1 = find_left(b)
	a1 = find_right(a, b1)
	print(abs(a1 - b1))


t = int(input())
for tt in range(t):
	x = input()
	y = input()
	b = list(reversed(y)).index('1')
	a = list(reversed(x))[b:].index('1')
	print(a)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	idx = b.rfind('1') + len(a) - len(b)
	idx2 = a.rfind('1', 0, idx + 1)
	print(str(idx - idx2) + '\n')


import math

class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	x = input()
	y = input()
	if x[-1] == '1' and y[-1] == '1':
		print(0)
		return
	col = 0
	check = False
	onr = 0
	for i in x[::-1]:
		if check and i == '1':
			break
		col += 1
		if i == '0':
			check = True
		if i == '1':
			onr += 1
	if not check:
		print(0)
		return
	t = 0
	for i in y[::-1]:
		if i == '1':
			break
		else:
			t += 1
	if onr > t:
		print(0)
		return
	onpos = 0
	for i in range(len(x) - t):
		if x[i] == '1':
			onpos = i
	v = len(x) - t - onpos - 1
	res = max(0, col - t)
	if res == 0:
		print(v)
	else:
		print(res)
query_count = Read.int()
for j in range(query_count):
	solve()


n = int(input())
for i in range(n):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	count = 0
	for j in y:
		if j == '1':
			break
		count += 1
	if count == len(y):
		print('0')
		continue
	count2 = count
	for j in x[count:]:
		if j == '1':
			break
		count2 += 1
	if count2 == len(x):
		print('0')
		continue
	print(count2 - count)


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	k = 0
	for i in range(len(y)):
		if y[i] == '1':
			break
	while i < len(x):
		if x[i] == '1':
			break
		i += 1
		k += 1
	print(k)


T = int(input())
for _ in range(T):
	x = input()[::-1]
	y = input()[::-1]
	idx = y.index('1')
	rls = 0
	while idx < len(x) and x[idx] != '1':
		rls += 1
		idx += 1
	print(rls)


def main():
	T = int(input())
	for _ in range(T):
		x = list(input())
		y = list(input())
		x.reverse()
		y.reverse()
		i_y = y.index('1')
		i_x = x.index('1', i_y)
		print(i_x - i_y)
main()


a = int(input())
for i in range(a):
	n = input()
	n = n[::-1]
	m = input()
	m = m[::-1]
	q = False
	w = False
	t = 0
	j = 0
	while q == False:
		if w == True:
			if n[t] == '1':
				q = True
			else:
				t += 1
		elif m[j] == '1':
			w = True
		else:
			t += 1
			j += 1
	print(t - j)


tests = int(input().strip())
for i in range(tests):
	xin = input().strip()
	yin = input().strip()
	lx = len(xin) - 1
	ly = len(yin) - 1
	for j in range(0, len(yin)):
		if yin[ly - j] == '1':
			c1 = j
			break
	a = lx - c1
	c2 = 0
	for j in range(a, -1, -1):
		if xin[j] == '1':
			c2 = a - j
			break
	print(c2)


for _ in range(int(input())):
	(x, y) = (input(), input())
	i = -1
	while y[i] == '0':
		i -= 1
	k = 0
	while x[i - k] == '0':
		k += 1
	print(k)


def solve():
	x = input()
	y = input()
	n = len(x)
	i = 1
	while y[-i] == '0':
		i += 1
	j = i
	while j < n and x[-j] == '0':
		j += 1
	return j - i
t = int(input())
for case in range(t):
	print(solve())


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	idx = b.index('1')
	idx2 = a.index('1', idx)
	print(idx2 - idx)


for i in range(int(input())):
	(x, y) = (input(), input())
	r = y.rfind('1')
	print(len(x) - len(y) + r - x.rfind('1', 0, len(x) - len(y) + r + 1))


for t in range(int(input())):
	a = list(map(int, str(input())))
	b = list(map(int, str(input())))
	x = 0
	a.reverse()
	b.reverse()
	c = b.index(1)
	for i in range(c, len(a)):
		if a[i] == 1:
			break
		else:
			x += 1
	print(x)


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	last1y = 0
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '1':
			break
		last1y += 1
	last1x = last1y
	for j in range(len(x) - 1 - last1y, -1, -1):
		if x[j] == '1':
			break
		last1x += 1
	print(last1x - last1y)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	posb = b.index('1')
	posa = a.index('1', posb)
	print(posa - posb)


for _ in range(int(input())):
	x = input()[-1::-1]
	y = input()[-1::-1]
	p1 = y.find('1')
	p2 = x[p1:].find('1') + p1
	print(p2 - p1)


t = int(input())
for nt in range(t):
	x = input()
	y = input()
	count = 0
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '0':
			count += 1
		else:
			break
	k = 0
	for i in range(len(x) - 1 - count, -1, -1):
		if x[i] == '1':
			break
		else:
			k += 1
	print(k)


t = int(input())
for i in range(t):
	a = input()[::-1]
	b = input()[::-1]
	j = 0
	while b[j] == '0':
		j += 1
	res = 0
	while a[j] == '0':
		j += 1
		res += 1
	print(res)


import sys
from collections import defaultdict

def main():
	T = int(input())
	for _ in range(T):
		x = input()[::-1]
		y = input()[::-1]
		posY = y.find('1')
		posX = posY
		while x[posX] != '1':
			posX += 1
		print(posX - posY)
main()


def read():
	s1 = input()
	s2 = input()
	return (s1, s2)

def solve(x, y):
	x = x[::-1]
	y = y[::-1]
	pos_y = y.index('1')
	pos_x = x.index('1', pos_y)
	return pos_x - pos_y
for i in range(int(input())):
	result = solve(*read())
	print(result)


for _ in range(int(input())):
	(x, y) = (input()[::-1], input()[::-1])
	iy = y.index('1')
	ix = x.index('1', iy)
	print(ix - iy)


def main():
	t = int(input())
	for i in range(t):
		x = input()
		y = input()
		i = -1
		count_y = 0
		while -i < len(y) and y[i] != '1':
			i -= 1
			count_y += 1
		i = -1
		ans = 0
		while -i < len(x) and (x[i] != '1' or -i <= count_y):
			i -= 1
			ans += 1
		print(max(ans - count_y, 0))
main()


for _ in range(int(input())):
	a = input()
	b = input()
	k1 = b[::-1].index('1')
	k = a[::-1][k1:].index('1')
	print(k)


n = int(input())
for _ in range(n):
	a = input()[::-1]
	b = input()[::-1]
	l = 0
	for i in range(len(b)):
		if b[i] == '1':
			l = i
			break
	m = 0
	for i in range(l, len(a)):
		if a[i] == '1':
			m = i
			break
	print(max(m - l, 0))


def find_k(x, y):
	count = 0
	while x > y:
		count += 1
		y += 1
	return count
n = int(input())
inp = []
while n:
	(x, y) = (input(), input())
	how_much_zero = y[::-1].count('0', 0, y[::-1].index('1'))
	new_x = x[0:len(x) - how_much_zero]
	nex_y = y[0:len(y) - how_much_zero]
	inp.append(find_k(new_x[::-1].index('1'), nex_y[::-1].index('1')))
	n -= 1
for i in inp:
	print(i)


t = int(input())
for i in range(t):
	x = input()[::-1]
	y = input()[::-1]
	cx = 0
	cy = 0
	while y[cy] == '0':
		cy += 1
	cx = cy
	while x[cx] == '0':
		cx += 1
	print(cx - cy)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	i = 0
	while y[i] != '1':
		i += 1
	b = i
	while x[i] != '1':
		i += 1
	a = i
	print(a - b)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import inf
for _ in range(int(input()) if True else 1):
	x = input()[::-1]
	y = input()[::-1]
	shifts = 0
	cur = 0
	i = 0
	while i < len(x):
		bit = y[cur]
		if bit == '0':
			cur += 1
		elif x[i] == '0':
			shifts += 1
		else:
			break
		i += 1
	print(shifts)


def mp():
	return map(int, input().split())
t = int(input())
for tt in range(t):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	x_i = x.find('1')
	y_i = y.find('1')
	if x_i >= y_i:
		print(x_i - y_i)
	else:
		for i in range(y_i, len(x)):
			if x[i] == '1':
				print(i - y_i)
				break


for _ in range(int(input())):
	s = input()
	s1 = input()
	c = c1 = 0
	for i in s1[::-1]:
		if i == '1':
			break
		else:
			c1 += 1
	i = len(s) - c1 - 1
	k = len(s) - c1 - 1
	while i > 0 and s[i] != '1':
		i -= 1
	print(k - i)


for t in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	posy = 0
	while y[posy] != '1':
		posy += 1
	posx = posy
	while x[posx] != '1':
		posx += 1
	ans = posx - posy
	print(ans)


n = int(input())

def solve(a, b):
	for (i, c) in enumerate(reversed(b)):
		if c == '1':
			break
	for (j, c) in enumerate(reversed(a[:len(a) - i])):
		if c == '1':
			break
	print(j)
for i in range(n):
	a = input()
	b = input()
	solve(a, b)


for _ in range(int(input())):
	x = input()
	y = input()
	y = y[::-1]
	x = x[::-1]
	in1 = y.index('1')
	print(x[in1:].index('1'))


n = int(input())
for k in range(n):
	x = [i for i in input()]
	y = [i for i in input()]
	if 1 == 0:
		print('a')
	else:
		lenx = len(x)
		leny = len(y)
		for iy in range(leny - 1, -1, -1):
			if y[iy] == '1':
				break
		indy = leny - iy
		for ix in range(lenx - 1, -1, -1):
			if x[ix] == '1':
				indx = lenx - ix
				if indy <= indx:
					print(indx - indy)
					break


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	tz = 0
	for c in reversed(y):
		if c == '1':
			break
		tz += 1
	best = 0
	for (i, c) in enumerate(reversed(x if tz == 0 else x[:-tz])):
		if c == '1':
			best = i
			break
	print(best)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y) = (str(input())[:-1][::-1], input()[:-1][::-1])
	pos_y = 0
	while y[pos_y] == '0':
		pos_y += 1
	pos_x = pos_y
	while x[pos_x] == '0':
		pos_x += 1
	print(pos_x - pos_y)


T = int(input())
for i in range(0, T):
	x = [int(j) for j in list(input())[::-1]]
	y = [int(j) for j in list(input())[::-1]]
	j = 0
	while y[j] != 1:
		j += 1
	k = j
	while x[k] != 1:
		k += 1
	print(k - j)


n = int(input())
for i in range(n):
	s1 = input()[::-1]
	s2 = input()[::-1]
	k = s2.index('1')
	ans = 0
	while s1[k] != '1':
		ans += 1
		k += 1
	print(ans)


t = int(input())
while t > 0:
	s1 = list(input())
	s2 = list(input())
	s1.reverse()
	s2.reverse()
	pos1 = pos2 = -1
	flag = False
	for i in range(len(s2)):
		if s2[i] == '1':
			pos2 = i
			break
	for i in range(len(s1)):
		if s1[i] == '1' and i >= pos2:
			print(i - pos2)
			break
	t -= 1


t = int(input())
while t > 0:
	l1 = list(input())
	l2 = list(input())
	k = []
	for i in range(len(l2)):
		if l2[i] == '1':
			k.append(i)
	k1 = max(k)
	k1 += len(l1) - len(l2)
	k2 = []
	for i in range(k1 + 1):
		if l1[i] == '1':
			k2.append(i)
	k3 = max(k2)
	print(k1 - k3)
	t = t - 1


n = int(input())
for i in range(n):
	s = input()[::-1]
	t = input()[::-1]
	print(s.find('1', t.find('1')) - t.find('1'))


T = int(input())
for t in range(T):
	n = input()
	m = input()
	n = list(n)
	m = list(m)
	n.reverse()
	m.reverse()
	i = 0
	while m[i] == '0':
		i += 1
	j = 0
	while n[i + j] == '0':
		j += 1
	print(j)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	x = input().rstrip()
	y = input().rstrip()
	for i in range(len(y) - 1, -1, -1):
		if y[i] == '1':
			a = i
			break
	c = 0
	for i in range(len(x) - (len(y) - a), -1, -1):
		if x[i] == '1':
			break
		c += 1
	print(c)


n = int(input())
for _ in range(n):
	x = input()[::-1]
	y = input()[::-1]
	ypos = y.index('1')
	xpos = x[ypos:].index('1') + ypos
	print(xpos - ypos)


t = int(input())
for i in range(t):
	x = input()
	y = input()
	x = [item for item in x]
	y = [item for item in y]
	x.reverse()
	y.reverse()
	a = 0
	b = 0
	while x[a] != '1':
		a += 1
	while y[b] != '1':
		b += 1
	if a >= b:
		print(a - b)
	else:
		a = b
		while x[a] != '1':
			a += 1
		print(a - b)


tasks = int(input())

def getOffset(string, start):
	i = 0
	while string[len(string) - 1 - i - start] == '0':
		i += 1
	return i
for x in range(tasks):
	bin1 = input()
	bin2 = input()
	offset_str2 = getOffset(bin2, 0)
	offset_str1 = getOffset(bin1, offset_str2)
	print(offset_str1)


import sys, os
from difflib import SequenceMatcher
from collections import Counter
from bisect import bisect_left as bl, bisect_right as br
from io import BytesIO, IOBase
from itertools import accumulate
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def memoize(f):

	class memodict(dict):

		def __getitem__(self, *key):
			return dict.__getitem__(self, key)

		def __missing__(self, key):
			ret = self[key] = f(*key)
			return ret
	return memodict().__getitem__
LCSubstr = lambda a, b: SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def extended_gcd(a, b):
	(s, old_s) = (0, 1)
	(r, old_r) = (b, a)
	while r:
		q = old_r // r
		(old_r, r) = (r, old_r - q * r)
		(old_s, s) = (s, old_s - q * s)
	return (old_r, old_s, (old_r - old_s * a) // b if b else 0)

def modinv(a, m):
	(g, x, _) = extended_gcd(a % m, m)
	return x % m if g == 1 else None

def make_nCr_mod(max_n=2 * 10 ** 5, mod=10 ** 9 + 7):
	max_n = min(max_n, mod - 1)
	(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

	def nCr_mod(n, r):
		res = 1
		while n or r:
			(a, b) = (n % mod, r % mod)
			if a < b:
				return 0
			res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
			n //= mod
			r //= mod
		return res
	return nCr_mod

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
			r = mid - 1
	return -1

def PrefixSum(arr):
	return list(accumulate(arr))

class inputs:

	def single(self):
		return int(input())

	def mul(self):
		return map(int, input().split())

	def list(self):
		return list(map(int, input().split()))
inp = inputs()

def main():
	for t in range(int(input())):
		x = input()[::-1]
		y = input()[::-1]
		I = 0
		J = 0
		for i in range(len(y)):
			if y[i] == '1':
				I = i
				break
		for i in range(i, len(x)):
			if x[i] == '1':
				J = i
				break
		print(J - I)
main()


n = int(input())
for _ in range(n):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	indb = 0
	for i in range(len(b)):
		if b[i] == '1':
			indb = i
			break
	inda = 0
	for i in range(indb, len(a)):
		if a[i] == '1':
			inda = i
			break
	print(max(inda - indb, 0))


def main():
	string1 = str(input())
	string1rev = string1[::-1]
	string2 = str(input())
	string2rev = string2[::-1]
	index = -1
	index2 = -1
	for i in range(len(string2rev)):
		if string2rev[i] == '1':
			index2 = i
			break
	for i in range(index2, len(string1rev)):
		if string1rev[i] == '1':
			index = i
			break
	print(abs(index - index2))

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


t = int(input())
while t > 0:
	t -= 1
	x = input()
	y = input()
	f = 0
	g = 0
	for i in range(len(y)):
		if y[len(y) - i - 1] == '1':
			f = i
			break
	for i in range(f, len(x)):
		if x[len(x) - i - 1] == '1':
			g = i
			break
	print(g - f)


for _ in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	p = y.find('1')
	q = x[p:].find('1')
	print(q)


t = int(input())
ans = list()
for _ in range(t):
	(x1, y1) = (input(), input())
	(x, y) = (str(), str())
	for n in x1:
		x = n + x
	for n in y1:
		y = n + y
	if len(x) < len(y):
		x = x + '0' * (len(y) - len(x))
	elif len(x) > len(y):
		y = y + '0' * (len(x) - len(y))
	(x_ind, y_ind) = (0, 0)
	for i in range(len(y)):
		if y[i] == '1':
			y_ind = i
			break
	for i in range(y_ind, len(x)):
		if x[i] == '1':
			x_ind = i
			break
	ans.append(x_ind - y_ind)
for a in ans:
	print(a)


for i in range(int(input())):
	s1 = input()
	s2 = input()
	a = 1
	b = 0
	for j in range(1, len(s2) + 1):
		if s2[-j] == '1':
			break
		else:
			a += 1
	if s1[-a] == '1' and s2[-a] == '1':
		print(0)
	else:
		for j in range(a + 1, len(s1) + 1):
			if s1[-j] == '1':
				print(j - a)
				break


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	lst = len(y) - y.rfind('1')
	out = False
	for i in range(lst, len(x) + 1):
		if x[-i] == '1':
			print(i - lst)
			out = True
			break
	if out:
		continue


T = int(input())
for k in range(T):
	x = input()
	y = input()
	(s, t) = (0, 0)
	for k in range(1, len(y) + 1):
		if y[-k] == '1':
			t = k
			break
	for k in range(t, len(x) + 1):
		if x[-k] == '1':
			s = k
			break
	print(s - t)


for _ in range(int(input())):
	a = input()
	b = input()
	b = b[::-1]
	a = a[::-1]
	s = b.index('1')
	t = a[s:].index('1')
	print(max(t, 0))


T = int(input())
while T > 0:
	x = input()[::-1]
	y = input()[::-1]
	posx = -1
	posy = -1
	i = 0
	while i < len(y):
		if y[i] == '1':
			posy = i
			break
		i += 1
	while i < len(x):
		if x[i] == '1':
			posx = i
			break
		i += 1
	print(posx - posy)
	T -= 1


for i in range(int(input())):
	(First, Second) = (input(), input())
	print(First[:len(First) - Second[::-1].index('1')][::-1].index('1'))


n = int(input())
for i in range(n):
	t1 = list(reversed(input()))
	t2 = list(reversed(input()))
	y = t2.index('1')
	x = t1.index('1', y)
	print(x - y)


n = int(input())
for i in range(n):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	q = y.find('1')
	k = x[q:].find('1')
	print(k)


read_int = lambda : int(input())
read_ints = lambda : list(map(int, input().split(' ')))

def solve(x: str, y: str):
	x_reverse = x[::-1]
	y_reverse = y[::-1]
	y_1 = y_reverse.find('1')
	x_1 = y_1 + x_reverse[y_1:].find('1')
	k = x_1 - y_1
	return k
T = read_int()
for i in range(T):
	x = input()
	y = input()
	result = solve(x, y)
	print(result, end='' if i == T - 1 else '\n')


t = int(input())
for i in range(t):
	x = input()
	y = input()
	num = y.rfind('1')
	if num != -1:
		if x.rfind('1') == -1:
			print(0)
		else:
			ans = 0
			for i in range(len(x) - len(y) + num, -1, -1):
				if x[i] == '1':
					ans = len(x) - len(y) + num - i
					break
			print(ans)
	else:
		print(0)


qw = []
for i in range(1, int(input()) + 1):
	(q, w) = (input()[::-1], input()[::-1])
	qw.append(q[w.index('1'):].index('1'))
print(*qw, sep='\n')


t = int(input())
for i in range(t):
	x = input()[::-1]
	y = input()[::-1]
	x1 = 0
	y1 = 0
	while y[y1] == '0':
		y1 += 1
	x1 = y1
	while x[x1] == '0':
		x1 += 1
	print(x1 - y1)


for u in range(int(input())):
	x = input()[::-1]
	y = input()[::-1]
	(a, b) = (0, 0)
	for i in range(len(y)):
		if y[i] == '1':
			a = i + 1
			break
	for i in range(len(x)):
		if x[i] == '1' and i + 1 >= a:
			b = i + 1
			break
	print(b - a)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	yp = -1
	while yp > -len(y) and y[yp] == '0':
		yp -= 1
	k = 0
	while yp - k > -len(x) and x[yp - k] == '0':
		k += 1
	print(k)


def leastSignificantBit(bitStr, startingFrom=0):
	for i in range(startingFrom, len(bitStr)):
		if bitStr[i] == '1':
			return i
	return -1
queries = int(input())
for q in range(queries):
	x = input()[::-1]
	y = input()[::-1]
	least_x = leastSignificantBit(x)
	least_y = leastSignificantBit(y)
	if least_x < least_y:
		least_x = leastSignificantBit(x, least_y)
	print(least_x - least_y)


def findLastIndex(str, start, end):
	x = '1'
	z = 0
	for i in range(end, start, -1):
		if str[i] == x:
			return z
		else:
			z += 1
	return -1
for _ in range(int(input())):
	a = input()
	b = input()
	bi = findLastIndex(b, -1, len(b) - 1)
	ai = findLastIndex(a, -1, len(a) - bi - 1)
	print(ai)


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	x = stdin.readline().strip()
	y = stdin.readline().strip()
	zer = 0
	for j in range(len(y) - 1, -1, -1):
		if y[j] == '0':
			zer += 1
		else:
			break
	ans = 0
	for j in range(len(x) - 1 - zer, -1, -1):
		if x[j] == '1':
			break
		ans += 1
	print(ans)


import sys
T = sys.stdin.readline()
for _i in range(0, int(T)):
	x = sys.stdin.readline().strip()
	y = sys.stdin.readline().strip()
	x_len = len(x)
	y_1_idx = 0
	y_len = len(y)
	i = y_len - 1
	while 0 <= i:
		if y[i] == '1':
			y_1_idx = y_len - i - 1
			break
		i -= 1
	i = x_len - y_1_idx - 1
	while 0 <= i:
		if x[i] == '1':
			break
		i -= 1
	print(x_len - y_1_idx - i - 1)


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		x = input().rstrip('\n')
		y = input().rstrip('\n')
		X = int(x, 2)
		Y = int(y, 2)
		ky = (Y & -Y).bit_length()
		for i in range(ky, len(x) + 1):
			if x[-i] == '1':
				k = i - ky
				break
		print(k)
main()


t = int(input())
for _ in range(t):
	s1 = input()[::-1]
	s2 = input()[::-1]
	pos2 = -1
	for (i, c) in enumerate(s2):
		if c == '1':
			pos2 = i
			break
	if pos2 == -1:
		print(0)
		continue
	ok = False
	for j in range(pos2, len(s1)):
		if s1[j] == '1':
			print(j - pos2)
			ok = True
			break
	if not ok:
		print(0)


R = lambda : input()[::-1]
for _ in range(int(input())):
	x = R()
	y = R()
	pos = y.index('1')
	for i in range(pos, len(x)):
		if x[i] == '1':
			print(i - pos)
			break


t = int(input())
for i in range(t):
	x = input()
	y = input()
	y = int(y, 2)
	i = 0
	while y % 2 == 0:
		y //= 2
		i += 1
	f = len(x)
	x = x[0:f - i]
	j = 0
	m = 0
	for i in x:
		if i == '1':
			m = j
		j += 1
	print(len(x) - m - 1)


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	x = x[::-1]
	y = y[::-1]
	posy = y.find('1')
	posx = x.find('1', posy)
	print(posx - posy)


for i in range(int(input())):
	(First, Second) = (input(), input())
	Index = len(Second) - 1
	Count = 0
	while Index > 0 and Second[Index] == '0':
		Index -= 1
		Count += 1
	First = First[::-1][Count:]
	print(First.index('1'))


T = int(input())
for _ in range(T):
	fx = input()
	fy = input()
	first_1 = 0
	i = 0
	while i < len(fy):
		if fy[len(fy) - 1 - i] == '1':
			first_1 = i
			break
		i += 1
	while fx[len(fx) - 1 - i] != '1':
		i += 1
	print(i - first_1)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
o = c.cin()
for x in range(o):
	n = c.cin(str)
	s = c.cin(str)
	dist = 0
	l2n = 0
	for j in range(len(s)):
		if s[j] == '1':
			l2n = len(s) - 1 - j
	for i in range(len(n) - l2n - 1, -1, -1):
		if n[i] == '1':
			dist = len(n) - l2n - 1 - i
			break
	print(dist)


import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
	x = input().strip()
	y = input().strip()
	for i in range(-1, -1 << 50, -1):
		if y[i] == '1':
			start = i
			break
	for i in range(i, -1 << 50, -1):
		if x[i] == '1':
			ans = i
			break
	print(start - ans)


t = int(input())
for _ in range(t):
	a = [int(x) for x in list(input())]
	b = [int(x) for x in list(input())]
	a.reverse()
	b.reverse()
	i = 0
	while True:
		if b[i] == 1:
			break
		i += 1
	j = i
	while True:
		if a[j] == 1:
			break
		j += 1
	print(j - i)


def main():
	for _ in range(int(input())):
		(a, b) = (input()[::-1] for _ in 'ab')
		i = b.find('1')
		j = a.find('1', i)
		print(j - i)
main()


import sys
T = int(sys.stdin.readline().strip())
for i in range(0, T):
	x = sys.stdin.readline().strip()
	y = sys.stdin.readline().strip()
	w = 0
	while y[-w - 1] == '0':
		w = w + 1
	v = w
	while x[-v - 1] == '0':
		v = v + 1
	print(v - w)


def find_first_one(y, from_=0):
	from_ = len(y) - 1 - from_
	for i in range(from_, -1, -1):
		if y[i] == '1':
			return len(y) - 1 - i
	return -1
t = int(input())
for i in range(t):
	(x, y) = (input(), input())
	y_one = find_first_one(y)
	x_one = find_first_one(x, y_one)
	print(x_one - y_one)


import sys

def main():
	N = int(sys.stdin.readline().strip())
	for _ in range(N):
		x = sys.stdin.readline().strip()[::-1]
		y = sys.stdin.readline().strip()[::-1]
		xp = x.find('1')
		yp = y.find('1')
		if xp < yp:
			xp = x.find('1', yp)
		print(xp - yp)
main()


t = int(input())
for ijk in range(0, t):
	x = input().strip()
	y = input().strip()
	i = -1
	while y[i] != '1':
		i -= 1
	w = i
	ans = 0
	while x[w] != '1':
		ans += 1
		w -= 1
	print(ans)


for rpt in range(int(input())):
	a = input()
	b = input()
	b1 = 0
	a1 = 0
	for i in range(len(b) - 1, -1, -1):
		if b[i] == '1':
			b1 = i
			break
	for i in range(len(a) - (len(b) - (b1 + 1)) - 1, -1, -1):
		if a[i] == '1':
			a1 = i
			break
	print(len(a) - (a1 + 1) - (len(b) - (b1 + 1)))


import io, os
n = int(input())
for i in range(n):
	a = input()
	b = input()
	k = 0
	for c in b[::-1]:
		if c == '1':
			break
		k += 1
	x = len(b) - k
	a1 = a[::-1]
	for i in range(k, len(a)):
		if a1[i] == '1':
			print(i - k)
			break


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	y_cnt = 0
	for c in reversed(y):
		if c == '0':
			y_cnt += 1
		else:
			break
	x_cnt = 0
	for c in reversed(x):
		if x_cnt < y_cnt:
			x_cnt += 1
			continue
		if c == '0':
			x_cnt += 1
		else:
			break
	print(x_cnt - y_cnt)


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD = pow(10, 9) + 7

def IN(f=0):
	if f == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
tc = IN(1)
for _ in range(tc):
	a = input()
	b = input()
	a = a[::-1]
	b = b[::-1]
	c = 0
	j = 0
	i = 0
	while j < len(b):
		if a[i] == '0' and b[j] == '1':
			i += 1
			c += 1
		elif a[i] == '1' and b[j] == '1':
			break
		else:
			i += 1
			j += 1
	print(c)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	n = len(b)
	second = 0
	for i in range(n - 1, -1, -1):
		if b[i] == '0':
			second += 1
		else:
			break
	n = len(a)
	first = second
	for i in range(n - second - 1, -1, -1):
		if a[i] == '0':
			first += 1
		else:
			break
	print(first - second)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	x = input()
	y = input()
	yfo = -1
	for k in range(len(y)):
		if y[len(y) - 1 - k] == '1':
			yfo = k
			break
	if yfo == -1:
		print(0)
		continue
	xfo = -1
	for j in range(yfo, len(x)):
		if x[len(x) - 1 - j] == '1':
			xfo = j
			break
	print(xfo - yfo)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def add_binary_nums(x, y):
	max_len = max(len(x), len(y))
	x = x.zfill(max_len)
	y = y.zfill(max_len)
	result = ''
	carry = 0
	for i in range(max_len - 1, -1, -1):
		r = carry
		r += 1 if x[i] == '1' else 0
		r += 1 if y[i] == '1' else 0
		result = ('1' if r % 2 == 1 else '0') + result
		carry = 0 if r < 2 else 1
	if carry != 0:
		result = '1' + result
	return result.zfill(max_len)

def main():
	for _ in range(int(input())):
		x = input()[::-1]
		y = input()[::-1]
		py = y.find('1')
		px = x.find('1', py)
		print(px - py)
	pass
main()