Read problems statements in Mandarin Chinese  and Russian. 

Chef likes to play games a lot. Gravity Guy is one such interesting game.
"Gravity Guy is an arcade side-scrolling game in which the player controls Gravity Guy by tapping the screen to switch gravity. The objective in this game is to run as far as possible while avoiding being trapped by obstacles, falling, or flying off the screen. If hit by obstacles, the game is over."
Chef is so addicted to this game that each night he dreams of himself being in the game as Gravity Guy. He has two lanes in front of him represented by two strings of equal length named as L_{1} and L_{2}. Each of the two lanes consists of some clean blocks represented by '.' and some dirty blocks represented by '#'.
Chef can start running from the beginning of any of the two lanes and cannot step over any dirty block ( '#' ) encountered during his journey. He has to complete his journey by reaching the end block of any of the two lanes.
Chef can use the following jumps to reach his destination. Considering chef is at x^{th} block of some lane.
He can jump to x+1^{th} block of the same lane.
He can switch gravity quickly and jump to x^{th} block of the other lane.
He can switch gravity and jump to x+1^{th} block of the other lane.
You have to tell him whether he can reach his destination or not. If it is possible for him to reach his destination, then Chef is interested in knowing the minimum number of gravity switches required to reach the destination.

------ Input ------ 

First line of input contains a single integer T denoting the number of test cases. Each test case consists of 2 lines. First line of each test case contains a string denoting lane L_{1}. Second line of each test case contains a string denoting lane L_{2}.

------ Output ------ 

For each test case, print "Yes" (without quotes) in the first line if Chef is able to reach the destination followed by a line containing an integer denoting minimum number of gravity switches required to reach to the destination. Print a single line containing the word "No" (without quotes) otherwise.

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ |L_{1}| ≤ 2 × 10^{5}, where |S| denotes the length of string S$
$|L_{1}| = |L_{2}|$

------ Subtasks ------ 

Subtask 1 (25 points)
$Sum of |L_{1}| over all test cases in one file it at most 200.$
$Only "Yes"/"No" response will be evaluated.$

Subtask 2 (25 points)
$Sum of |L_{1}| over all test cases in one file it at most 200.$

Subtask 3 (25 points)
$Sum of |L_{1}| over all test cases in one file it at most 10^{6}.$
$Only "Yes"/"No" response will be evaluated.$

Subtask 4 (25 points)
$Sum of |L_{1}| over all test cases in one file it at most 10^{6}.$

----- Sample Input 1 ------ 
3
#...#
.###.
#.#.#.
.#.#.#
#...
#...
----- Sample Output 1 ------ 
Yes

2

Yes

5

No
----- explanation 1 ------ 
Test case $1$: Chef will start his journey from $L_{2}$. He switches gravity and jumps to $L_{1}$. He continues on $L_{1}$ till block $4$ and then again switch gravity and jump to block $5$ of $L_{2}$. Therefore, he requires total $2$ gravity switches to reach the destination.

Test case $2$: Chef will start his journey from $L_{2}$. He switches gravity and jumps to second block of $L_{1}$. He switches gravity and jumps to third block of $L_{2}$. He switches gravity and jumps to fourth block of $L_{1}$. He switches gravity and jumps to fifth block of $L_{2}$. He switches gravity and jumps to sixth block of $L_{1}$. Therefore, he requires total $5$ gravity switches to reach the destination.

Test case $3$: Chef cannot start his journey as starting block of both the lanes $L_{1}$ and $L_{2}$ are dirty and he cannot step over them.

Source: codechef | Difficulty: MEDIUM
Tags: Dynamic programming

Greedy algorithms


Solutions:
t = int(input())
for i in range(t):
	a = input()
	b = input()
	c = 0
	arr = [a, b]
	z = 0
	yon = True
	for k in range(len(a)):
		if arr[z][k] == '#':
			c += 1
			z = (z + 1) % 2
			if arr[z][k] == '#':
				yon = False
				c = 2 * 10 ** 5
				break
	c2 = 0
	z = 1
	yon2 = True
	for k in range(len(a)):
		if arr[z][k] == '#':
			c2 += 1
			z = (z + 1) % 2
			if arr[z][k] == '#':
				yon2 = False
				c2 = 2 * 10 ** 5
				break
	if yon or yon2:
		print('Yes')
		print(min(c, c2))
	else:
		print('No')


import sys
sys.setrecursionlimit(2000000)

def dp_jump(lane_num, ind, lane, cache, n):
	if ind == n - 1 and lane[lane_num][ind] != '#':
		cache[lane_num][ind] = 0
		return cache[lane_num][ind]
	elif ind >= n:
		return float('inf')
	elif cache[lane_num][ind] != None:
		return cache[lane_num][ind]
	else:
		if lane[lane_num][ind] == '#':
			cache[lane_num][ind] = float('inf')
			return cache[lane_num][ind]
		horz = dp_jump(lane_num, ind + 1, lane, cache, n)
		vertforw = dp_jump(lane_num ^ 1, ind + 1, lane, cache, n) + 1
		cache[lane_num][ind] = min(horz, vertforw)
		return cache[lane_num][ind]
test = int(input())
while test:
	lane = []
	lane.append(sys.stdin.readline().rstrip('\n'))
	lane.append(sys.stdin.readline().rstrip('\n'))
	n = len(lane[0])
	cache = [[None for _ in range(n)] for __ in range(2)]
	dp_jump(0, 0, lane, cache, n)
	dp_jump(1, 0, lane, cache, n)
	if cache[0][0] == float('inf') and cache[1][0] == float('inf'):
		print('No')
	else:
		print('Yes')
		print(min(cache[0][0], cache[1][0]))
	test -= 1


t = int(input())
for _ in range(t):
	l1 = list(input())
	l2 = list(input())
	l = [l1, l2]
	n = len(l1)
	ans = [[10 ** 6] * n for i in range(2)]
	if l1[0] == '.':
		ans[0][0] = 0
	if l2[0] == '.':
		ans[1][0] = 0
	if l1[0] == '#' and l2[0] == '#':
		print('No')
		continue
	for i in range(1, n):
		for j in range(2):
			if l[j][i] == '.':
				ans[j][i] = min(min(ans[j][i - 1], min(ans[(j + 1) % 2][i - 1], ans[(j + 1) % 2][i]) + 1), 10 ** 6)
	ans = min(ans[0][-1], ans[1][-1])
	if ans >= 10 ** 6:
		print('No')
	else:
		print('Yes')
		print(ans)


In = 1 << 30
for i in range(int(input())):
	L1 = input()
	L2 = input()
	Ans = 0
	Curr = 0
	for (l1, l2) in zip(L1, L2):
		if l1 == l2 == '#':
			Ans = In
			break
		if l1 == '#':
			if Curr == 1:
				Ans += 1
			Curr = 2
		if l2 == '#':
			if Curr == 2:
				Ans += 1
			Curr = 1
	if Ans >= In:
		print('No')
	else:
		print('Yes')
		print(Ans)


t = int(input())
while t:
	l1 = input()
	l2 = input()
	n = len(l1)

	def minGravity(s1, s2):
		n = len(s1)
		arr = [0] * 2
		arr[0] = s1
		arr[1] = s2
		s1Dirty = n
		s2Dirty = n
		for i in range(n):
			if s1[i] == '#':
				s1Dirty = i
				break
		for i1 in range(n):
			if s2[i1] == '#':
				s2Dirty = i1
				break
		if s1Dirty == n or s2Dirty == n:
			return 0
		lane = 0
		if s1Dirty > s2Dirty:
			lane = 0
			swiches = 0
			for i in range(n):
				if arr[lane][i] == '#':
					swiches += 1
					lane = lane ^ 1
			return swiches
		lane = 1
		swiches = 0
		for i in range(n):
			if arr[lane][i] == '#':
				swiches += 1
				lane = lane ^ 1
		return swiches

	def possible(s1, s2):
		for i in range(len(s1)):
			if s1[i] == '#' and s1[i] == s2[i]:
				return False
		return True
	if not possible(l1, l2):
		print('No')
	else:
		print('Yes')
		print(minGravity(l1, l2))
	t -= 1


def ret_val(s1, s2):
	n = len(s1)
	change = 0
	lane = 0
	if '#' not in s1:
		return change
	if '#' not in s2:
		return change
	x1 = s1.index('#')
	x2 = s2.index('#')
	if x1 > x2:
		lane = 1
	elif x1 < x2:
		lane = 2
	else:
		return -1
	for i in range(1, n):
		if s1[i] == s2[i] and s1[i] == '#':
			return -1
		elif lane == 1 and s1[i] == '#':
			lane = 2
			change += 1
		elif lane == 2 and s2[i] == '#':
			lane = 1
			change += 1
	return change
t = int(input())
for _ in range(t):
	res = ret_val(input(), input())
	if res == -1:
		print('No')
	else:
		print('Yes')
		print(res)


INF = 1 << 30
for _ in range(int(input())):
	l1 = input()
	l2 = input()
	d1 = d2 = 0
	for (i, j) in zip(l1, l2):
		(d1, d2) = (INF if i == '#' else min(d1, d2 + 1), INF if j == '#' else min(d2, d1 + 1))
	ans = min(d1, d2)
	if ans >= INF:
		print('No')
	else:
		print('Yes')
		print(ans)


for _ in range(int(input())):
	s = str(input())
	p = str(input())
	pos = ''
	ans = 0
	imp = 0
	start = 0
	for i in range(len(s)):
		if start == 0:
			if s[i] == '#' and p[i] != '#':
				pos = 'p'
				start = 1
			elif p[i] == '#' and s[i] != '#':
				pos = 's'
				start = 1
			elif s[i] == p[i] == '#':
				imp = 1
				break
		elif pos == 's':
			if s[i] == '#':
				if p[i] != '#':
					pos = 'p'
					ans += 1
				else:
					imp = 1
					break
			else:
				None
		elif p[i] == '#':
			if s[i] != '#':
				pos = 's'
				ans += 1
			else:
				imp = 1
				break
		else:
			None
	if imp == 1:
		print('No')
	else:
		print('Yes')
		print(ans)


for _ in range(int(input())):
	a = input()
	b = input()
	l = len(a)
	x = a.find('#')
	y = b.find('#')
	if x == -1 or y == -1:
		print('Yes')
		print('0')
		continue
	if a[-1] == '#' and b[-1] == '#' or (a[0] == '#' and b[0] == '#'):
		print('No')
		continue
	if x == y:
		count1 = 0
		current = 0
		for i in range(l - 1):
			if current:
				if b[i + 1] == '#':
					if a[i + 1] == '.':
						current = 0
						count1 += 1
					elif a[i] == '.':
						current = 0
						count1 += 1
					else:
						count1 = float('inf')
						break
			elif a[i + 1] == '#':
				if b[i + 1] == '.':
					current = 1
					count1 += 1
				elif b[i] == '.':
					current = 1
					count1 += 1
				else:
					count1 = float('inf')
					break
		count2 = 0
		current = 1
		for i in range(l - 1):
			if current:
				if b[i + 1] == '#':
					if a[i + 1] == '.':
						current = 0
						count2 += 1
					elif a[i] == '.':
						current = 0
						count2 += 1
					else:
						count2 = float('inf')
						break
			elif a[i + 1] == '#':
				if b[i + 1] == '.':
					current = 1
					count2 += 1
				elif b[i] == '.':
					current = 1
					count2 += 1
				else:
					count2 = float('inf')
					break
		if count1 == count2 == float('inf'):
			print('No')
		else:
			print('Yes')
			print(min(count1, count2))
		continue
	if x < y:
		current = 1
	else:
		current = 0
	count = 0
	for i in range(l - 1):
		if current:
			if b[i + 1] == '#':
				if a[i + 1] == '.':
					current = 0
					count += 1
				elif a[i] == '.':
					current = 0
					count += 1
				else:
					print('No')
					break
		elif a[i + 1] == '#':
			if b[i + 1] == '.':
				current = 1
				count += 1
			elif b[i] == '.':
				current = 1
				count += 1
			else:
				print('No')
				break
	else:
		print('Yes')
		print(count)


T = int(input())
for z in range(T):
	path1 = list(input())
	path2 = list(input())
	distances1 = [999999 for i in range(len(path1))]
	distances2 = [999999 for i in range(len(path1))]
	if path1[0] == '#' and path2[0] == '#':
		print('No')
		continue
	if path1[0] == '.':
		distances1[0] = 0
	if path2[0] == '.':
		distances2[0] = 0
	impossible = False
	for i in range(0, len(path1) - 1):
		if path1[i + 1] == '#' and path2[i + 1] == '#':
			impossible = True
			break
		if path1[i + 1] == '.':
			distances1[i + 1] = min(distances1[i], distances2[i] + 1)
		else:
			distances1[i + 1] = 9999999
		if path2[i + 1] == '.':
			distances2[i + 1] = min(distances1[i] + 1, distances2[i])
		else:
			distances2[i + 1] = 9999999
	if impossible:
		print('No')
	else:
		print('Yes')
		print(min(distances1[-1], distances2[-1]))


T = int(input())
for i in range(T):
	s = input()
	s2 = input()
	yo = True
	for i in range(len(s)):
		if s[i] == s2[i] == '#':
			yo = False
	if yo == False:
		print('No')
	else:
		swaps = 0
		first = -1
		second = -1
		for i in range(len(s)):
			if s[i] == '#':
				first = i
				break
		for i in range(len(s)):
			if s2[i] == '#':
				second = i
				break
		if '#' not in s or '#' not in s2:
			swaps = 0
		elif first > second:
			curr_lane = 0
			for i in range(len(s)):
				if s[i] == '#' and curr_lane == 0:
					swaps += 1
					curr_lane = 1 - curr_lane
				elif s2[i] == '#' and curr_lane == 1:
					swaps += 1
					curr_lane = 1 - curr_lane
		else:
			curr_lane = 1
			for i in range(len(s)):
				if s[i] == '#' and curr_lane == 0:
					swaps += 1
					curr_lane = 1 - curr_lane
				elif s2[i] == '#' and curr_lane == 1:
					swaps += 1
					curr_lane = 1 - curr_lane
		print('Yes')
		print(swaps)


ma = 10 ** 6
for _ in range(int(input())):
	s1 = input()
	s2 = input()
	l1 = [ma for i in range(len(s1))]
	l2 = [ma for i in range(len(s2))]
	if s1[0] == '.':
		l1[0] = 0
	if s2[0] == '.':
		l2[0] = 0
	for i in range(len(s1)):
		if l1[i] < ma and s1[i] == '.':
			if s2[i] == '.':
				l2[i] = min(l2[i], 1 + l1[i])
			if i < len(s1) - 1:
				if s1[i + 1] == '.':
					l1[i + 1] = min(l1[i + 1], l1[i])
				if s2[i + 1] == '.':
					l2[i + 1] = min(l2[i + 1], l1[i] + 1)
		if l2[i] < ma and s2[i] == '.':
			if s1[i] == '.':
				l1[i] = min(l1[i], 1 + l2[i])
			if i < len(s2) - 1:
				if s1[i + 1] == '.':
					l1[i + 1] = min(l1[i + 1], l2[i] + 1)
				if s2[i + 1] == '.':
					l2[i + 1] = min(l2[i + 1], l2[i])
	if l1[-1] >= ma and l2[-1] >= ma:
		print('No')
	else:
		print('Yes')
		print(min(l1[-1], l2[-1]))


import sys
INF = sys.maxsize
for cas in range(int(input())):
	L1 = input()
	L2 = input()
	ans = 0
	curr = 0
	for (L1x, L2x) in zip(L1, L2):
		if L1x == L2x == '#':
			ans = INF
			break
		if L1x == '#':
			if curr == 1:
				ans += 1
			curr = 2
		if L2x == '#':
			if curr == 2:
				ans += 1
			curr = 1
	if ans >= INF:
		print('No')
	else:
		print('Yes')
		print(ans)


for _ in range(int(input())):
	(l1, l2, simp) = (input(), input(), 0)
	for i in range(len(l1)):
		if l1[i] == '#' and l2[i] == '#':
			print('No')
			simp = 1
			break
	if simp == 0:
		(cnt, cake) = (0, 0)
		for i in range(len(l2)):
			if cake == 0:
				if l2[i] == '#':
					f = 1
					cake = 1
				elif l1[i] == '#':
					f = 0
					cake = 1
			elif f == 1:
				if l1[i] != '.':
					cnt += 1
					f = 0
				else:
					pass
			elif l2[i] != '.':
				cnt += 1
				f = 1
			else:
				pass
		print('Yes', cnt, sep='\n')


for _ in range(int(input())):
	l1 = input()
	l2 = input()
	if l1[0] == '#':
		if l2[0] == '#':
			print('No')
			continue
		else:
			start = 2
	elif l2[0] == '#':
		start = 1
	else:
		start = 0
	switch = 0
	i = f = 0
	while i < len(l1):
		(a, b) = (l1[i], l2[i])
		if a == '#' and b == '#':
			f = 1
			break
		elif start == 0 and (a == '#' or b == '#'):
			if a == '#':
				start = 2
			else:
				start = 1
		elif start == 1 and a == '#':
			start = 2
			switch += 1
		elif start == 2 and b == '#':
			start = 1
			switch += 1
		i += 1
	if f == 1:
		print('No')
	else:
		print('Yes')
		print(switch)


for _ in range(int(input())):
	l1 = input()
	l2 = input()
	curr = 0
	numb = 1
	n = len(l1)
	u = False
	if l1[0] == '.' and l2[0] == '#':
		curr = 1
	elif l2[0] == '.' and l1[0] == '#':
		curr = 2
	elif l1[0] == '.' and l2[0] == '.':
		i = 0
		while l1[i] == '.' and l2[i] == '.':
			i += 1
			if i == n:
				print('Yes')
				print(0)
				u = True
				break
		numb = i
		if not u:
			if l1[i] == '.' and l2[i] == '#':
				curr = 1
			elif l2[i] == '.' and l1[i] == '#':
				curr = 2
			else:
				print('No')
				u = True
	else:
		print('No')
		u = True
	ans = 0
	if not u:
		for i in range(numb, n):
			if l1[i] == '#' and l2[i] == '#':
				print('No')
				u = True
				break
			if curr == 1:
				if l1[i] == '#':
					curr = 2
					ans += 1
			elif l2[i] == '#':
				curr = 1
				ans += 1
		if not u:
			print('Yes')
			print(ans)


for _ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	i = -1
	flag = True
	currentlane = 0
	jumps = 0
	if '#' in a and '#' in b:
		if a.index('#') > b.index('#'):
			currentlane = 0
		else:
			currentlane = 1
		while i < n - 1:
			if a[i + 1] == '#' and b[i + 1] == '#':
				flag = False
				break
			if currentlane == 0:
				if a[i + 1] == '.':
					i += 1
				elif b[i + 1] == '.':
					jumps += 1
					i += 1
					currentlane = 1
			elif b[i + 1] == '.':
				i += 1
			elif a[i + 1] == '.':
				jumps += 1
				i += 1
				currentlane = 0
	if flag:
		print('Yes')
		print(jumps)
	else:
		print('No')


n = int(input())
for _ in range(n):
	a = list(input())
	b = list(input())
	flag = False
	tr = 0
	for (i, j) in zip(a, b):
		if tr == 0:
			if i == '#':
				tr = 2
			if j == '#':
				tr = 1
		if i == '#' and j == '#':
			print('No')
			flag = True
			break
	if flag:
		flag = False
		continue
	count = 0
	if tr == 2:
		switch = False
	else:
		switch = True
	for i in range(len(a)):
		if switch:
			if a[i] == '#':
				count += 1
				switch = False
		elif b[i] == '#':
			count += 1
			switch = True
	print('Yes')
	print(count)


for t in range(int(input())):
	l1 = list(input().strip())
	l2 = list(input().strip())
	n = len(l1)
	l = [[l1[i], l2[i]] for i in range(n)]
	flag = True
	if l1[0] == '#' and l2[0] == '#' or (l1[-1] == '#' and l2[-1] == '#'):
		print('No')
		continue
	ptr = 1 if l[0][1] == '.' else 0
	ctr = ctr1 = 0
	if l[0][0] == l[0][1]:
		ptr1 = 0
		for i in range(n - 1):
			if l[i + 1][ptr] == '#':
				if l[i + 1][1 - ptr] == '#':
					flag = False
					break
				else:
					ctr += 1
					ptr = 1 - ptr
			if l[i + 1][ptr1] == '#':
				if l[i + 1][1 - ptr1] == '#':
					flag = False
					break
				else:
					ctr1 += 1
					ptr1 = 1 - ptr1
		print('Yes\n{}'.format(min(ctr, ctr1))) if flag else print('No')
	else:
		for i in range(n - 1):
			if l[i + 1][ptr] == '#':
				if l[i + 1][1 - ptr] == '#':
					flag = False
					break
				else:
					ctr += 1
					ptr = 1 - ptr
		print('Yes\n{}'.format(ctr)) if flag else print('No')


def solve(one, two):
	dis = 0
	switch = 0
	on = one
	notOn = two
	possible = True
	while dis <= N - 1 and possible:
		if on[dis] == '.':
			dis += 1
		elif notOn[dis] == '.':
			dis += 1
			switch += 1
			(on, notOn) = (notOn, on)
		else:
			possible = False
	if possible == False:
		return -1
	else:
		return switch
for _ in range(int(input())):
	first = input()
	second = input()
	N = len(first)
	if '#' not in first:
		print('Yes')
		print(0)
	elif '#' not in second:
		print('Yes')
		print(0)
	else:
		p = solve(first, second)
		q = solve(second, first)
		if p + q == -2:
			print('No')
		else:
			print('Yes')
			if p < 0:
				print(q)
			elif q < 0:
				print(p)
			else:
				print(min(p, q))


from math import inf
import sys
for _ in range(int(input())):
	l1 = input()
	l2 = input()
	cl1 = l1
	cl2 = l2
	s1 = s2 = 0
	ol = lambda l, l1, l2: l1 if l == l2 else l2
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			print('No')
			break
		if cl1[i] == '#':
			cl1 = ol(cl1, l1, l2)
			s1 += 1
		if cl2[i] == '#':
			cl2 = ol(cl2, l1, l2)
			s2 += 1
	else:
		print('Yes')
		print(min(s1, s2))


INF = 1 << 30
for i in range(int(input())):
	L1 = input()
	L2 = input()
	ans = 0
	curr = 0
	for (l1, l2) in zip(L1, L2):
		if l1 == l2 == '#':
			ans = INF
			break
		if l1 == '#':
			if curr == 1:
				ans += 1
			curr = 2
		if l2 == '#':
			if curr == 2:
				ans += 1
			curr = 1
	if ans >= INF:
		print('No')
	else:
		print('Yes')
		print(ans)


def func(cur, other):
	i = 0
	cnt = 0
	n = len(cur)
	while i < n - 1:
		if cur[i + 1] == '.':
			i += 1
		elif other[i + 1] == '#':
			return 'No'
			break
		else:
			i += 1
			(cur, other) = (other, cur)
			cnt += 1
	return cnt
t = int(input())
for _ in range(t):
	l1 = input()
	l2 = input()
	n = len(l1)
	if l1[0] == '.' and l2[0] == '#':
		val = func(l1, l2)
		if val != 'No':
			print('Yes')
		print(val)
	elif l1[0] == '#' and l2[0] == '.':
		val = func(l2, l1)
		if val != 'No':
			print('Yes')
		print(val)
	elif l1[0] == '#' and l2[0] == '#':
		print('No')
	else:
		a = func(l1, l2)
		b = func(l2, l1)
		if a == 'No' and b == 'No':
			print('No')
		else:
			print('Yes')
			try:
				print(min(a, b))
			except:
				if a == 'No':
					print(b)
				else:
					print(a)


t = int(input())
for _ in range(t):
	st = [input(), input()]
	n = len(st[0])
	exec = True
	for i in range(n):
		if st[0][i] == st[1][i] == '#':
			print('No')
			exec = False
			break
	if exec:
		print('Yes')
		dp = [[0 for _ in range(n + 1)] for _ in range(2)]
		for i in range(1, n + 1):
			if st[0][i - 1] == '#':
				dp[0][i] = 10 ** 18
			else:
				dp[0][i] = min(dp[0][i - 1], 1 + dp[1][i - 1])
			if st[1][i - 1] == '#':
				dp[1][i] = 10 ** 18
			else:
				dp[1][i] = min(1 + dp[0][i - 1], dp[1][i - 1])
		print(min(dp[0][n], dp[1][n]))


__author__ = 'Ronald Kaiser'
__email__ = 'raios dot catodicos at gmail dot com'
from math import inf
import sys
for _ in range(int(input())):
	l1 = input()
	l2 = input()
	cl1 = l1
	cl2 = l2
	s1 = s2 = 0
	ol = lambda l, l1, l2: l1 if l == l2 else l2
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			print('No')
			break
		if cl1[i] == '#':
			cl1 = ol(cl1, l1, l2)
			s1 += 1
		if cl2[i] == '#':
			cl2 = ol(cl2, l1, l2)
			s2 += 1
	else:
		print('Yes')
		print(min(s1, s2))


UPPER = 0
LOWER = 1

def main():
	T = int(input())
	for i in range(T):
		lanes = (input(), input())
		upper_obstacle = lanes[UPPER].find('#')
		if upper_obstacle == -1:
			print('Yes')
			print(0)
			continue
		lower_obstacle = lanes[LOWER].find('#')
		if lower_obstacle == -1:
			print('Yes')
			print(0)
			continue
		if upper_obstacle < lower_obstacle:
			current_lane = LOWER
		else:
			current_lane = UPPER
		progress = 0
		completion = len(lanes[UPPER]) - 1
		switches_used = 0
		if lanes[current_lane][progress] == '#':
			print('No')
			continue
		while progress < completion:
			if lanes[current_lane][progress + 1] == '.':
				progress += 1
				continue
			elif lanes[(current_lane + 1) % 2][progress + 1] == '.':
				progress += 1
				current_lane = (current_lane + 1) % 2
				switches_used += 1
				continue
			else:
				break
		else:
			print('Yes')
			print(switches_used)
			continue
		print('No')
main()


T = int(input())
for _ in range(0, T):
	L1 = input()
	L2 = input()
	temp = 0
	for i in range(0, len(L1)):
		if L1[i] == '#' and L2[i] == '#':
			temp = 1
			break
	if temp != 0:
		print('No')
	else:
		ans1 = 4 * len(L1) + 100
		ans2 = 4 * len(L1) + 100
		if L1[0] == '.':
			c = 0
			ans1 = 0
			for i in range(1, len(L1)):
				if c == 0:
					if L1[i] == '#':
						c = 1
						ans1 = ans1 + 1
				elif L2[i] == '#':
					c = 0
					ans1 = ans1 + 1
		if L2[0] == '.':
			c = 0
			ans2 = 0
			for i in range(1, len(L2)):
				if c == 0:
					if L2[i] == '#':
						c = 1
						ans2 = ans2 + 1
				elif L1[i] == '#':
					c = 0
					ans2 = ans2 + 1
		print('Yes')
		print(min(ans1, ans2))


for t in range(int(input())):
	s1 = input()
	s2 = input()
	n = len(s1)
	f = 0
	for i in range(n):
		if s1[i] == s2[i] == '#':
			f = 1
	if f == 1:
		print('No')
		continue
	c = 0
	flag = -1
	for i in range(0, n):
		if s1[i] == '#':
			if flag == 0:
				c += 1
			flag = 1
		if s2[i] == '#':
			if flag == 1:
				c += 1
			flag = 0
	print('Yes')
	print(c)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	n = len(s1)
	ls1 = [0] * n
	ls2 = [0] * n
	ls1[0] = 0 if s1[0] == '.' else int(10000000.0)
	ls2[0] = 0 if s2[0] == '.' else int(10000000.0)
	for i in range(1, n):
		ls1[i] = min(ls1[i - 1], ls2[i - 1] + 1) if s1[i] == '.' else int(10000000.0)
		ls2[i] = min(ls2[i - 1], ls1[i - 1] + 1) if s2[i] == '.' else int(10000000.0)
	ans = min(ls1[n - 1], ls2[n - 1])
	print('{}\n{}'.format('Yes', ans)) if ans < int(10000000.0) else print('No')


t = int(input())
for _ in range(t):
	l1 = list(input())
	l2 = list(input())
	flag = 0
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')
		dp1 = [0] * (len(l1) + 1)
		dp1[0] = 0
		dp2 = [0] * (len(l1) + 1)
		dp2[0] = 0
		for i in range(1, len(l1) + 1):
			if l1[i - 1] == '#':
				dp1[i] = 10 ** 18
			else:
				dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
			if l2[i - 1] == '#':
				dp2[i] = 10 ** 18
			else:
				dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
		print(min(dp1[len(l1)], dp2[len(l1)]))


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	f = 1
	n = len(s1)
	for i in range(n):
		if s1[i] == s2[i] == '#':
			f = 0
	if f == 0:
		print('No')
		continue
	cnt = 0
	if s1[0] == '.':
		mauka = 0
	else:
		mauka = 1
	mauka = -1
	for i in range(n):
		if s1[i] == '#':
			if mauka == 0:
				cnt += 1
			mauka = 1
		if s2[i] == '#':
			if mauka == 1:
				cnt += 1
			mauka = 0
	print('Yes')
	print(cnt)


import sys

def perform():
	lane_1 = list(input())
	lane_2 = list(input())
	lane_len = len(lane_1)
	pos = False
	min_switch = sys.maxsize
	lanes = [lane_1, lane_2]
	if lane_1[0] != '#':
		t_pos = True
		t_switch = 0
		cur_lane = 0
		for i in range(lane_len):
			if lanes[cur_lane][i] == '#':
				t = 0
				if cur_lane == 0:
					t = 1
				if lanes[t][i] == '.':
					t_switch += 1
					cur_lane = t
				else:
					t_pos = False
					break
		if t_pos:
			pos = True
			min_switch = min(min_switch, t_switch)
	if lane_2[0] != '#':
		t_pos = True
		t_switch = 0
		cur_lane = 1
		for i in range(lane_len):
			if lanes[cur_lane][i] == '#':
				t = 0
				if cur_lane == 0:
					t = 1
				if lanes[t][i] == '.':
					t_switch += 1
					cur_lane = t
				else:
					t_pos = False
					break
		if t_pos:
			pos = True
			min_switch = min(min_switch, t_switch)
	if pos:
		print('Yes')
		print(min_switch)
	else:
		print('No')
for _ in range(int(input())):
	perform()


for t in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	if a[0] == '#' and b[0] == '#':
		print('No')
		continue
	f1 = 1
	c1 = 0
	j = 1
	if a[0] == '.':
		for i in range(1, n):
			if a[i] == '#' and b[i] == '#':
				f1 = 0
				break
			if j == 1 and a[i] == '.':
				continue
			elif j == 2 and b[i] == '.':
				continue
			else:
				if j == 1:
					j = 2
				else:
					j = 1
				c1 += 1
	else:
		f1 = 0
	c2 = 0
	j = 2
	f2 = 1
	if b[0] == '.':
		for i in range(1, n):
			if a[i] == '#' and b[i] == '#':
				f2 = 0
				break
			if j == 1 and a[i] == '.':
				continue
			elif j == 2 and b[i] == '.':
				continue
			else:
				if j == 1:
					j = 2
				else:
					j = 1
				c2 += 1
	else:
		f2 = 0
	if f1 and f2:
		print('Yes')
		print(min(c1, c2))
	elif f1 == 1:
		print('Yes')
		print(c1)
	elif f2 == 1:
		print('Yes')
		print(c2)
	else:
		print('No')


import sys
for _ in range(int(input())):
	a1 = list(input())
	a2 = list(input())
	count = 0
	DP1 = [0] * len(a1)
	DP2 = [0] * len(a1)
	n = len(a1)
	for i in range(n):
		if a1[i] == '#' and a2[i] == '#':
			print('No')
			count = 1
			break
	if count != 1:
		if a1[0] == '#':
			DP1[0] = sys.maxsize
		if a2[0] == '#':
			DP2[0] = sys.maxsize
		for i in range(1, n):
			if a1[i] != '#':
				DP1[i] = min(DP1[i - 1], DP2[i - 1] + 1)
			else:
				DP1[i] = sys.maxsize
			if a2[i] != '#':
				DP2[i] = min(DP2[i - 1], DP1[i - 1] + 1)
			else:
				DP2[i] = sys.maxsize
		print('Yes')
		re = min(DP1[-1], DP2[-1])
		print(re)


for __ in range(int(input())):
	a1 = input()
	a2 = input()
	dp1 = [0] * len(a1)
	dp2 = [0] * len(a1)
	count = 0
	j = 0
	while j < len(a1):
		if a1[j] == '#' and a2[j] == '#':
			count = 1
			print('No')
			break
		j += 1
	if count != 1:
		if a1[0] == '#':
			dp1[0] = 10 ** 10
		if a2[0] == '#':
			dp2[0] = 10 ** 10
		for i in range(1, len(a1)):
			if a1[i] != '#':
				dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
			else:
				dp1[i] = 10 ** 10
			if a2[i] != '#':
				dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
			else:
				dp2[i] = 10 ** 10
		print('Yes')
		m = min(dp1[-1], dp2[-1])
		print(m)


t = int(input())
for i in range(t):
	l1 = input()
	l2 = input()
	n = len(l1)
	dp1 = []
	dp2 = []
	for y in range(n):
		dp1.append(0)
		dp2.append(0)
	c = 0
	for k in range(0, n):
		if l1[k] == '#' and l2[k] == '#':
			c = 1
			break
	if c == 0:
		if l1[0] == '#':
			dp1[0] = 10 ** 10
		if l2[0] == '#':
			dp2[0] = 10 ** 10
		if l1[-1] == '#':
			dp1[-1] = 10 ** 10
		if l2[-1] == '#':
			dp2[-1] = 10 ** 10
		for j in range(1, n):
			if l1[j] == '#':
				dp1[j] = 10 ** 10
			if l2[j] == '#':
				dp2[j] = 10 ** 10
			if l1[j] != '#':
				dp1[j] = min(dp1[j - 1], dp2[j - 1] + 1)
			if l2[j] != '#':
				dp2[j] = min(dp2[j - 1], dp1[j - 1] + 1)
		x = min(dp1[-1], dp2[-1])
		print('Yes')
		print(x)
	elif c == 1:
		print('No')


for _ in range(int(input())):
	l = input()
	s = input()
	flag = 'Yes'
	bad = 10000000000
	for i in range(len(l)):
		if l[i] == '#' and s[i] == '#':
			flag = 'No'
			print('No')
			break
	if flag == 'Yes':
		n = len(l)
		dp1 = [0] * n
		dp2 = [0] * n
		if l[0] == '#':
			dp1[0] = bad
		if s[0] == '#':
			dp2[0] = bad
		for i in range(1, n):
			if l[i] == '#':
				dp1[i] = bad
			else:
				dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
			if s[i] == '#':
				dp2[i] = bad
			else:
				dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
		if min(dp1[-1], dp2[-1]) < 10 ** 6:
			print('Yes')
			print(min(dp1[-1], dp2[-1]))
		else:
			print('No')


t = int(input())
for m in range(t):
	l1 = input()
	l2 = input()
	k = len(l1)
	dp1 = [0] * k
	dp2 = [0] * k
	c = 0
	for i in range(k):
		if l1[i] == '#' and l2[i] == '#':
			c = 1
			print('No')
			break
	if c != 1:
		if l1[0] == '#':
			dp1[0] = 10 ** 9
		if l2[0] == '#':
			dp2[0] = 10 ** 9
		for i in range(1, k):
			if l1[i] != '#':
				dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
			else:
				dp1[i] = 10 ** 9
			if l2[i] != '#':
				dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
			else:
				dp2[i] = 10 ** 9
		print('Yes')
		print(min(dp1[-1], dp2[-1]))


import sys
for t in range(int(input())):
	l1 = input()
	l2 = input()
	dp1 = []
	dp2 = []
	lengt = len(l1)
	for i in range(lengt):
		dp1.append(0)
		dp2.append(0)
	c = 0
	for i in range(len(l1)):
		if l1[i] == '#' and l2[i] == '#':
			c = 1
			print('No')
			break
	if c != 1:
		if l1[0] == '#':
			dp1[0] = sys.maxsize
		if l2[0] == '#':
			dp2[0] = sys.maxsize
		for i in range(1, len(l1)):
			if l1[i] != '#':
				dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
			else:
				dp1[i] = sys.maxsize
			if l2[i] != '#':
				dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
			else:
				dp2[i] = sys.maxsize
		print('Yes')
		print(min(dp1[-1], dp2[-1]))


def m(l1, l2):
	l1 = [i for i in l1]
	l2 = [i for i in l2]
	dp1 = [0] * len(l1)
	dp2 = [0] * len(l2)
	for i in range(len(l1)):
		if l1[i] == '#' and l2[i] == '#':
			return ['No']
	if l1[0] == '#':
		dp1[0] = 10 ** 9
	if l2[0] == '#':
		dp2[0] = 10 ** 9
	if l1[-1] == '#':
		dp1[-1] = 10 ** 9
	if l2[-1] == '#':
		dp2[-1] = 10 ** 9
	for i in range(1, len(l1)):
		if l1[i] == '#':
			dp1[i] = 10 ** 9
		if l2[i] == '#':
			dp2[i] = 10 ** 9
		if l1[i] != '#':
			dp1[i] = min(int(dp1[i - 1]), int(dp2[i - 1] + 1))
		if l2[i] != '#':
			dp2[i] = min(int(dp2[i - 1]), int(dp1[i - 1] + 1))
	return ['Yes', min(dp1[-1], dp2[-1])]
t = int(input())
while t:
	l1 = input()
	l2 = input()
	li = m(l1, l2)
	if len(li) == 1:
		print('No')
	else:
		print(li[0])
		print(li[1])
	t -= 1


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	s1 = [i for i in s1]
	s2 = [i for i in s2]
	k = len(s1)
	dp1 = [0] * k
	dp2 = [0] * k
	f = 0
	for i in range(k):
		if s1[i] == '#' and s2[i] == '#':
			print('No')
			f = 1
			break
	if f:
		continue
	if s1[0] == '#':
		dp1[0] = 10 ** 9
	if s2[0] == '#':
		dp2[0] = 10 ** 9
	if s2[-1] == '#':
		dp2[-1] = 10 ** 9
	if s1[-1] == '#':
		dp1[-1] = 10 ** 9
	for i in range(1, k):
		if s1[i] == '#':
			dp1[i] = 10 ** 9
		if s2[i] == '#':
			dp2[i] = 10 ** 9
		if s2[i] != '#':
			dp2[i] = min(int(dp1[i - 1] + 1), int(dp2[i - 1]))
		if s1[i] != '#':
			dp1[i] = min(int(dp2[i - 1] + 1), int(dp1[i - 1]))
	print('Yes')
	print(min(dp1[-1], dp2[-1]))


import sys
for t in range(int(input())):
	s1 = input()
	s2 = input()
	leng = len(s1)
	f = 0
	for i in range(leng):
		if s1[i] == '#' and s2[i] == '#':
			print('No')
			f = 1
			break
	if f != 1:
		l1 = []
		l2 = []
		for i in range(leng):
			l1.append(0)
			l2.append(0)
		if s1[0] == '#':
			l1[0] = sys.maxsize
		if s2[0] == '#':
			l2[0] = sys.maxsize
		for i in range(1, leng):
			if s1[i] == '#':
				l1[i] = sys.maxsize
			else:
				l1[i] = min(l1[i - 1], l2[i - 1] + 1)
			if s2[i] == '#':
				l2[i] = sys.maxsize
			else:
				l2[i] = min(l2[i - 1], l1[i - 1] + 1)
		print('Yes')
		print(min(l1[-1], l2[-1]))


T = int(input())
for _ in range(T):
	l1 = list(input())
	l2 = list(input())
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			print('No')
			break
	else:
		print('Yes')
	dp1 = [0] * len(l1)
	dp2 = [0] * len(l1)
	if l1[0] == '#':
		dp1[0] = 1000000
	else:
		dp1[0] = 0
	if l2[0] == '#':
		dp2[0] = 1000000
	else:
		dp2[0] = 0
	for i in range(1, len(l1)):
		if l1[i] == '#':
			dp1[i] = 1000000
		else:
			dp1[i] = min(dp1[i - 1], dp2[i - 1] + 1)
		if l2[i] == '#':
			dp2[i] = 1000000
		else:
			dp2[i] = min(dp2[i - 1], dp1[i - 1] + 1)
	val = min(dp1[-1], dp2[-1])
	if val < 1000000:
		print(val)


for h in range(int(input())):
	L1 = input()
	L2 = input()
	L1obs = [0 for i in range(len(L1))]
	L2obs = [0 for i in range(len(L2))]
	L1counter = 0
	L2counter = 0
	valid = 1
	for i in range(1, len(L1) + 1):
		if L1[-i] == '.' and L2[-i] == '.':
			L1counter += 1
			L2counter += 1
		elif L1[-i] == '#' and L2[-i] == '#':
			valid = 0
			break
		elif L1[-i] == '.':
			L1counter += 1
			L2counter = 0
		else:
			L2counter += 1
			L1counter = 0
		L1obs[-i] = L1counter
		L2obs[-i] = L2counter
	if valid == 0:
		print('No')
		continue
	currentIndex = 0
	currentArray = 1
	i = 0
	jumpCount = 0
	extra = 1
	if L1obs[i] > L2obs[i]:
		currentArray = 1
	else:
		currentArray = 2
	while i <= len(L1) - 1:
		if currentArray == 1:
			i += L1obs[i] + 1
			currentArray = 2
		else:
			i += L2obs[i] + 1
			currentArray = 1
		if i > len(L1):
			break
		jumpCount += 1
	print('Yes')
	print(jumpCount)


def sfidx(ls, a):
	try:
		return ls.index('#')
	except:
		return len(ls)
for _ in range(int(input())):
	L1 = list(input().strip())
	L2 = list(input().strip())
	cmp = [L1, L2]
	lin = 0 if sfidx(L1, '#') > sfidx(L2, '#') else 1
	sw = 0
	block = False
	for a in range(len(L1)):
		if cmp[lin][a] == '#':
			lin = 1 - lin
			sw += 1
			if cmp[lin][a] == '#':
				block = True
				break
	if block:
		print('No')
	else:
		print('Yes')
		print(sw)


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	gr = 0
	flag = 99999999999999999
	cur = 0
	for i in range(len(s1)):
		if s1[i] == s2[i] == '#':
			gr = flag
			break
		elif s1[i] == '#':
			if cur == 1:
				gr += 1
			cur = 2
		elif s2[i] == '#':
			if cur == 2:
				gr += 1
			cur = 1
	if gr == flag:
		print('No')
	else:
		print('Yes')
		print(gr)


import math
t = int(input())
for k in range(t):
	s1 = input()
	s2 = input()
	flag = 0
	n = len(s1)
	dp1 = []
	dp2 = []
	for i in range(n):
		if s1[i] == s2[i] == '#':
			print('No')
			break
	else:
		print('Yes')
		if s1[0] == '#':
			dp1.append(math.inf)
		else:
			dp1.append(0)
		if s2[0] == '#':
			dp2.append(math.inf)
		else:
			dp2.append(0)
		for i in range(1, n):
			if s1[i] == '#':
				dp1.append(math.inf)
			else:
				dp1.append(min(dp1[i - 1], dp2[i - 1] + 1))
			if s2[i] == '#':
				dp2.append(math.inf)
			else:
				dp2.append(min(dp2[i - 1], dp1[i - 1] + 1))
		res = min(dp1[n - 1], dp2[n - 1])
		print(res)


val = 10 ** 7
t = int(input().strip())
for i in range(t):
	str1 = input().strip()
	str2 = input().strip()
	n = len(str1)
	dp = [[val for i in range(2)] for j in range(n)]
	if str1[0] == '#' and str2[0] == '#':
		print('No')
	else:
		if str1[0] == '.':
			dp[0][0] = 0
		if str2[0] == '.':
			dp[0][1] = 0
		for i in range(1, n):
			if str1[i] == '.':
				dp[i][0] = min(dp[i - 1][0], dp[i - 1][1] + 1)
			else:
				dp[i][0] = val
			if str2[i] == '.':
				dp[i][1] = min(dp[i - 1][0] + 1, dp[i - 1][1])
		min1 = min(dp[n - 1][0], dp[n - 1][1])
		if min1 < val:
			print('Yes')
			print(min1)
		else:
			print('No')


t = int(input())
while t:
	t = t - 1
	a = input()
	b = input()
	c = 0
	f = 0
	s = 0
	for i in range(len(a)):
		if a[i] == '#' and c != 'b':
			if c == 0:
				c = 'b'
			elif b[i] == '#':
				f = 1
				break
			else:
				s = s + 1
				c = 'b'
		if b[i] == '#' and c != 'a':
			if c == 0:
				c = 'a'
			elif a[i] == '#':
				f = 1
				break
			else:
				s = s + 1
				c = 'a'
	if f == 0:
		print('Yes')
		print(s)
	else:
		print('No')


for t in range(int(input())):
	s = []
	s.append(input())
	s.append(input())
	n = len(s[0])
	flag = [0, 0]
	count = [0, 0]
	lane = 0
	i = 0
	switch = 0
	if s[0][0] == '#':
		flag[0] = 1
	else:
		while i < n - 1:
			x = (lane + 1) % 2
			if s[lane][i + 1] == '.':
				i += 1
				switch = 0
				continue
			elif s[x][i] == '.':
				lane = x
				count[0] += 1
				if switch == 0:
					switch = 1
				else:
					flag[0] = 1
					break
				continue
			elif s[x][i + 1] == '.':
				lane = x
				count[0] += 1
				i += 1
				switch = 0
				continue
			else:
				flag[0] = 1
				break
	lane = 1
	i = 0
	switch = 0
	if s[1][0] == '#':
		flag[1] = 1
	else:
		while i < n - 1:
			x = (lane + 1) % 2
			if s[lane][i + 1] == '.':
				i += 1
				switch = 0
				continue
			elif s[x][i] == '.':
				lane = x
				count[1] += 1
				if switch == 0:
					switch += 1
				else:
					flag[1] = 1
					break
				continue
			elif s[x][i + 1] == '.':
				lane = x
				count[1] += 1
				i += 1
				switch = 0
				continue
			else:
				flag[1] = 1
				break
	if flag[0] == 1 and flag[1] == 1:
		print('No')
	elif flag[0] == 1 and flag[1] == 0:
		print('Yes')
		print(count[1])
	elif flag[0] == 0 and flag[1] == 1:
		print('Yes')
		print(count[0])
	else:
		print('Yes')
		print(min(count))


cases = int(input())
for _ in range(cases):
	top = '.' + input()
	bottom = '.' + input()
	array = [top, bottom]
	tfind = top.find('#')
	bfind = bottom.find('#')
	if (tfind > bfind and bfind != -1) | (tfind == -1):
		start = 0
	else:
		start = 1
	count = 0
	ok = True
	for index in range(len(top) - 1):
		if array[start][index + 1] == '.':
			continue
		start = (start + 1) % 2
		count += 1
		if array[start][index + 1] == '.':
			continue
		else:
			ok = False
			break
	if ok:
		print('Yes')
		print(count)
	else:
		print('No')


def solve(lanes):
	lanelength = len(lanes[0])
	dp = [[False] * lanelength, [False] * lanelength]
	for pos in range(lanelength):
		for lane in (0, 1):
			if not pos:
				dp[lane][pos] = lanes[lane][pos] == '.'
				continue
			else:
				dp[lane][pos] = (lanes[lane][pos] == '.') & any([dp[0][pos - 1], dp[1][pos - 1]])
		if lanes[0][pos] == lanes[1][pos] == '#':
			break
	if dp[0][-1] or dp[1][-1]:
		print('Yes')
	else:
		print('No')
		return
	switches = [0, 0]
	for start_lane in (0, 1):
		current_lane = start_lane
		for pos in range(lanelength):
			if not dp[current_lane][pos]:
				(current_lane, switches[start_lane]) = (1 - current_lane, switches[start_lane] + 1)
	print(min(switches))
number_test_cases = int(input())
for _ in range(number_test_cases):
	lane1 = input()
	lane2 = input()
	solve([lane1, lane2])


t = int(input())
while t > 0:
	a = input()
	b = input()
	l = len(a)
	flag = 1
	for i in range(l):
		if a[i] == '#' and b[i] == '#':
			flag = 0
			break
	if flag == 1:
		if a[0] == '.':
			count1 = 0
			start = 'a'
			i = 0
			while i < l:
				if start == 'a':
					while a[i] == '.':
						if i == l - 1:
							i = l
							break
						i = i + 1
					if i < l:
						start = 'b'
						count1 = count1 + 1
				elif start == 'b':
					while b[i] == '.':
						if i == l - 1:
							i = l
							break
						i = i + 1
					if i < l:
						start = 'a'
						count1 = count1 + 1
		else:
			count1 = 9999999
		if b[0] == '.':
			count2 = 0
			start = 'b'
			i = 0
			while i < l:
				if start == 'a':
					while a[i] == '.':
						if i == l - 1:
							i = l
							break
						i = i + 1
					if i < l:
						start = 'b'
						count2 = count2 + 1
				elif start == 'b':
					while b[i] == '.':
						if i == l - 1:
							i = l
							break
						i = i + 1
					if i < l:
						start = 'a'
						count2 = count2 + 1
		else:
			count2 = 9999999
		print('Yes')
		print(min(count1, count2))
	if flag == 0:
		print('No')
	t = t - 1


def solve():
	num_test = int(input())
	for i in range(num_test):
		test_case()

def test_case():
	lane1 = input()
	lane2 = input()
	destination = find_destination(lane1, lane2)
	if len(destination) == 1:
		print('No')
	else:
		print('Yes')
		print(destination[1])

def find_destination(lane1, lane2):
	jump = 0
	dest_reached = 'Y'
	current_lane = ''
	other_lane = ''
	currnet_pos = 0
	first_dirty_lane1 = lane1.find('#')
	first_dirty_lane2 = lane2.find('#')
	if first_dirty_lane1 == -1 or first_dirty_lane2 == -1:
		return ['Y', 0]
	if first_dirty_lane1 >= first_dirty_lane2:
		(current_lane, other_lane) = (lane1, lane2)
		currnet_pos = first_dirty_lane1
	else:
		(current_lane, other_lane) = (lane2, lane1)
		currnet_pos = first_dirty_lane2
	for i in range(currnet_pos, len(lane1)):
		if current_lane[i] == '#' and other_lane[i] == '#':
			dest_reached = 'N'
			break
		if current_lane[i] == '#':
			(current_lane, other_lane) = (other_lane, current_lane)
			jump += 1
	if dest_reached == 'N':
		return ['N']
	else:
		return ['Y', jump]
solve()


import sys

def calculate(m, x):
	resp = 0
	if m[x][0] == '#':
		return len(m[x]) + 1
	for i in range(0, len(m[0]) - 1):
		if m[x][i + 1] == '#':
			if m[(x + 1) % 2][i + 1] == '#':
				return len(m[x]) + 1
			else:
				x = (x + 1) % 2
				resp += 1
	return resp

def solve(m):
	resp = min(calculate(m, 0), calculate(m, 1))
	return -1 if resp == len(m[0]) + 1 else resp
T = int(input())
m = ['', '']
for i in range(T):
	m[0] = input()
	m[1] = input()
	resp = solve(m)
	if resp == -1:
		print('No')
	else:
		print('Yes\n{0}'.format(resp))


def test(l1, l2):
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			return 'No'
	return 'Yes'

def farest(l):
	i = 0
	while i < len(l) and l[i] == '.':
		i += 1
	return i - 1

def minop(l1, l2):
	c = 0
	if l2[0] == '.':
		if l1[0] == '#':
			(l1, l2) = (l2, l1)
		elif farest(l2) > farest(l1):
			(l1, l2) = (l2, l1)
	for i in range(1, len(l1)):
		if l1[i] == '#':
			c += 1
			(l1, l2) = (l2, l1)
	return c
l = []
nb = int(input())
for i in range(nb):
	l.append([input(), input()])
for i in range(nb):
	x = test(l[i][0], l[i][1])
	print(x)
	if x == 'Yes':
		print(minop(l[i][0], l[i][1]))


test = int(input())
l1 = []
l2 = []
for j in range(0, test):
	l1 = input()
	l2 = input()
	x = 1
	y = 0
	c = 0
	for i in range(0, len(l1)):
		if l1[i] == '.' and l2[i] == '#':
			if x == 2:
				x = 1
				y = y + 1
		elif l2[i] == '.' and l1[i] == '#':
			if x == 1:
				x = 2
				y = y + 1
		elif l1[i] == '.' and l2[i] == '.':
			continue
		else:
			print('No')
			c = 1
			break
		i = i + 1
	x = 2
	z = 0
	for i in range(0, len(l1)):
		if l2[i] == '.' and l1[i] == '#':
			if x == 1:
				x = 2
				z = z + 1
		elif l1[i] == '.' and l2[i] == '#':
			if x == 2:
				x = 1
				z = z + 1
		else:
			continue
	if c != 1:
		print('Yes')
		if y > z:
			print(z)
		else:
			print(y)


def test(l1, l2):
	for i in range(len(l1)):
		if l1[i] == l2[i] == '#':
			return 'No'
	return 'Yes'

def farest(l):
	i = 0
	while i < len(l) and l[i] == '.':
		i += 1
	return i - 1

def switch(x):
	return 'l1' if x == 'l2' else 'l2'

def affect(x, l1, l2):
	return l1 if x == 'l1' else l2

def minop(l1, l2):
	c = 0
	x = ['l1', 0]
	if l1[0] == '.' and l2[0] == '.':
		x[0] = 'l2' if farest(l2) > farest(l1) else 'l1'
	elif l2[0] == '.':
		x[0] = 'l2'
	l = affect(x[0], l1, l2)
	for i in range(1, len(l1)):
		if l[i] == '.':
			x[1] += 1
		else:
			c += 1
			x[0] = switch(x[0])
			l = affect(x[0], l1, l2)
			x[1] += 1
	return c
nb = int(input())
for i in range(nb):
	l1 = input()
	l2 = input()
	print(test(l1, l2))
	print(minop(l1, l2)) if test(l1, l2) == 'Yes' else None