Given two strings consisting of lowercase english alphabets, the task is to check whether these strings are meta strings or not. Meta strings are the strings which can be made equal by exactly one swap in any of the strings. Equal string are not considered here as Meta strings.
Example 1:
Input:
S1 = "geeks", S2 = "keegs"
Output: 1
Explanation: We can swap the 0th and 3rd
character of S2 to make it equal to S1.
Ã¢â¬â¹Example 2:
Input: 
S1 = "geeks", S2 = "geeks"
Output: 0
Explanation: Equal strings are not considered
Meta strings.
Your Task:
You don't need to read input or print anything. Your task is to complete the function metaStrings() which takes the strings S1 and S2 as input and returns true if both the strings are meta strings, else it returns false.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1<=|S|<=10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).

Starter code:
#User function Template for python3
class Solution:
    def metaStrings(self, S1, S2):
        # code here

Solutions:
class Solution:

	def metaStrings(self, S1, S2):
		c = []
		if len(S1) == len(S2):
			for i in range(len(S1)):
				if S1[i] != S2[i]:
					c.append(ord(S1[i]) - ord(S2[i]))
		else:
			return 0
		if len(c) == 2 and abs(c[0]) == abs(c[1]):
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		c = 0
		k1 = {}
		k2 = {}
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				c += 1
				k1[S1[i]] = 1
				k2[S2[i]] = 1
				if c > 2:
					return 0
		if k1 == k2 and c == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, s1, s2):
		if len(s1) != len(s2) or s1 == s2:
			return 0
		(i, j, k) = (-1, -1, -1)
		for l in range(len(s1)):
			if s1[l] != s2[l] and i == -1:
				i = l
			elif s1[l] != s2[l] and i != -1:
				j = l
			elif s1[l] != s2[l] and i != -1 and (j != -1):
				return 0
		return 1 if s1[i] == s2[j] and s1[j] == s2[i] else 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2) or S1 == S2:
			return 0
		m = 0
		d = {}
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				d[S1[i]] = S2[i]
				if len(d) > 2:
					return 0
		for i in d:
			if d[i] in d:
				if i == d[d[i]]:
					return 1
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		first = None
		second = None
		if len(S1) != len(S2):
			return 0
		for x in range(len(S1)):
			if S1[x] != S2[x]:
				if first is None:
					first = x
				elif second is None:
					second = x
				else:
					return 0
		if first is not None and second is not None:
			if S1[first] == S2[second] and S1[second] == S2[first]:
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		count = 0
		if S1 == S2:
			return False
		if set(S1) != set(S2):
			return False
		if len(S1) != len(S2):
			return False
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				count += 1
		if count == 2:
			return True
		return False


class Solution:

	def metaStrings(self, S1, S2):
		n = len(S1)
		if len(S1) != len(S2) or S1 == S2:
			return 0
		l = []
		for i in range(n):
			if S1[i] == S2[i]:
				pass
			else:
				l.append(i)
		if len(l) == 2 and S1[l[0]] == S2[l[1]]:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		m = list(S1)
		n = list(S2)
		if S1 == S2:
			return 0
		if sorted(m) == sorted(n):
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		res = []
		for i in range(len(S2)):
			if S2[i] != S1[i]:
				res.append(i)
		if len(res) > 2 or len(res) < 2:
			return 0
		S2 = list(S2)
		(S2[res[0]], S2[res[1]]) = (S2[res[1]], S2[res[0]])
		S2 = ''.join(S2)
		if S1 == S2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		ind = []
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				ind.append(i)
		if len(ind) == 2:
			z = S1[:ind[0]] + S1[ind[-1]] + S1[ind[0] + 1:ind[-1]] + S1[ind[0]] + S1[ind[-1] + 1:]
			if z == S2:
				return True
			else:
				return False
		else:
			False


class Solution:

	def metaStrings(self, S1, S2):
		count = 0
		if S1 == S2 or len(S1) != len(S2):
			return 0
		else:
			for i in range(0, len(S1)):
				if S1[i] not in S2:
					return 0
				elif S1[i] != S2[i]:
					count = count + 1
		if count == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, s1, s2):
		if s1 == s2:
			return 0
		if len(s1) != len(s2):
			return 0
		count = 0
		for i in range(len(s1)):
			if s1[i] not in s2 or s2[i] not in s1:
				return 0
			elif s1[i] != s2[i]:
				count += 1
		if count == 2:
			return True
		else:
			return False


class Solution:

	def metaStrings(self, S1, S2):
		s1_len = len(S1)
		s2_len = len(S2)
		if s1_len != s2_len:
			return False
		(prev, curr) = (-1, -1)
		count = 0
		for i in range(s1_len):
			if S1[i] != S2[i]:
				count += 1
				if count > 2:
					return False
				prev = curr
				curr = i
		return count == 2 and S1[prev] == S2[curr] and (S1[curr] == S2[prev])


class Solution:

	def metaStrings(self, S1, S2):
		c = 0
		l = []
		a = []
		for i in range(0, len(S1)):
			a.append(S2[i])
			if S1[i] != S2[i]:
				c = c + 1
				l.append(i)
		if len(l) == 2 and c != 0:
			(a[l[0]], a[l[1]]) = (a[l[1]], a[l[0]])
			if S1 == ''.join((x for x in a)):
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		count = 0
		a = list(S1)
		b = list(S2)
		a.sort()
		b.sort()
		if a != b:
			return 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				count += 1
		if count == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		l = 0
		p1 = -1
		p2 = -1
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				l += 1
				if p1 == -1:
					p1 = i
				else:
					p2 = i
		if l != 2:
			return False
		if S1[p1] != S2[p2] or S1[p2] != S2[p1]:
			return False
		return True


class Solution:

	def metaStrings(self, S1, S2):
		c = 0
		for i in range(0, len(S1)):
			if S1[i] not in S2:
				return 0
			if S1[i] != S2[i]:
				c += 1
		if c == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		(mismatch, cnt) = (-1, 0)
		for i in range(len(S1)):
			if S1[i] != S2[i] and mismatch == -1:
				(mismatch, cnt) = (i, 1)
			elif S1[i] != S2[i] and mismatch != -1 and (cnt == 1) and (S1[i] == S2[mismatch]) and (S1[mismatch] == S2[i]):
				cnt = 2
			elif S1[i] != S2[i]:
				return 0
		if cnt == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, s1, s2):
		if len(s1) == 2:
			if s1[0] == s2[1] and s2[0] == s1[1]:
				return True
		if len(s1) != len(s2) or len(s1) < 3 or s1 == s2:
			return False
		l = []
		i = 0
		k = 0
		for j in range(len(s1)):
			if s1[j] != s2[j]:
				l.append(j)
		if len(l) > 2:
			return False
		if s1[l[0]] == s2[l[1]] and s1[l[1]] == s2[l[0]]:
			return True
		else:
			return False


class Solution:

	def metaStrings(self, S1, S2):
		if sorted(S1) != sorted(S2):
			return 0
		c = 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				c += 1
		if c == 0:
			return 0
		return 1


class Solution:

	def metaStrings(self, s1, s2):
		a = []
		b = []
		if len(s1) != len(s2):
			return False
		for i in range(len(s1)):
			if s1[i] != s2[i]:
				b.append(s1[i])
				a.append(s2[i])
		if len(a) != 2:
			return False
		a.sort()
		b.sort()
		if a == b:
			return True


class Solution:

	def metaStrings(self, S1, S2):
		i = 0
		n = len(S1)
		count = 0
		sum1 = 0
		sum2 = 0
		if len(S1) == len(S2):
			for i in range(0, n):
				if S1[i] == S2[i]:
					count += 1
				sum1 += ord(S1[i])
				sum2 += ord(S2[i])
			if count == n - 2 and sum1 == sum2:
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def metaStrings(self, a, b):
		n = len(a)
		c = 0
		(x, y) = ('', '')
		for i in range(n):
			if a[i] != b[i]:
				if c == 0:
					x = a[i]
					y = b[i]
					c += 1
				elif c == 1 and x == b[i] and (y == a[i]):
					c += 1
				else:
					return False
		if c == 2:
			return True
		return False


class Solution:

	def metaStrings(self, s1, s2):
		if s1 == s2:
			return 0
		swap = None
		for (i, char) in enumerate(s1):
			if s2[i] != char:
				if swap == None:
					swap = char
				elif swap == -1:
					return 0
				elif swap == s2[i]:
					swap = -1
				else:
					return 0
		if swap == -1:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return False
		arr1 = list(S1)
		arr2 = list(S2)
		dict1 = {}
		dict2 = {}
		for key in S1:
			dict1[key] = dict1.get(key, 0) + 1
		for key in S2:
			dict2[key] = dict2.get(key, 0) + 1
		for key in dict1:
			if key in dict2:
				if dict1[key] != dict2[key]:
					return False
			else:
				return False
		count = 0
		for i in range(len(S1)):
			if arr1[i] != arr2[i]:
				count += 1
				if count == 2:
					return True
		return False


class Solution:

	def metaStrings(self, S1, S2):
		(n, m) = (len(S1), len(S2))
		if n != m:
			return False
		prev = curr = -1
		count = 0
		for i in range(n):
			if S1[i] != S2[i]:
				count += 1
				if count > 2:
					return False
				prev = curr
				curr = i
		return count == 2 and S1[prev] == S2[curr] and (S1[curr] == S2[prev])


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return False
		s1 = []
		s2 = []
		s1.extend(S1)
		s2.extend(S2)
		diffs = []
		for i in range(len(S1)):
			if len(diffs) > 2:
				return False
			if s1[i] != s2[i]:
				diffs.append(i)
		if len(diffs) != 2:
			return False
		if s2[diffs[0]] == s1[diffs[1]] and s2[diffs[1]] == s1[diffs[0]]:
			return True


from collections import Counter

class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2 or len(S1) != len(S2):
			return False
		count = 0
		for i in range(len(S1)):
			count += S1[i] != S2[i]
		return count == 2 and Counter(S1) == Counter(S2)


class Solution:

	def metaStrings(self, S1, S2):
		(n1, n2) = (len(S1), len(S2))
		if n1 != n2:
			return False
		else:
			count = 0
			from collections import Counter
			d = Counter(S1) - Counter(S2)
			n = len(d)
			for (i, j) in zip(S1, S2):
				if i != j:
					count += 1
			if count == 2 and n == 0:
				return True
			else:
				return False


class Solution:

	def metaStrings(self, S1, S2):
		S1 = list(S1)
		S2 = list(S2)
		if S1 == S2:
			return False
		n = len(S1)
		m = len(S2)
		if n != m:
			return 0
		i = 0
		j = n - 1
		while S1[i] == S2[i]:
			i += 1
		while S1[j] == S2[j]:
			j -= 1
		(S1[i], S1[j]) = (S1[j], S1[i])
		if S1 == S2:
			return True
		return False


class Solution:

	def metaStrings(self, S1, S2):
		c = 0
		(k, l) = (0, 0)
		if S1 == S2 or len(S1) != len(S2):
			return 0
		for i in S1:
			if i not in S2:
				k = 1
		for i in S2:
			if i not in S1:
				l = 1
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				c = c + 1
		if k == 1 or l == 1:
			return 0
		elif c == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		n = len(S1)
		if n != len(S2):
			return 0
		index = []
		for i in range(n):
			if S1[i] != S2[i]:
				index.append(i)
		if len(index) != 2:
			return 0
		return S1[index[0]] == S2[index[1]] and S2[index[0]] == S1[index[1]]


class Solution:

	def metaStrings(self, S1, S2):
		li = []
		if len(S1) != len(S2) or S1 == S2:
			return 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				li.append(S1[i])
				li.append(S2[i])
		if len(li) == 4:
			li.sort()
			if li[0] == li[1] and li[2] == li[3]:
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2) or S1 == S2:
			return False
		elif S1 == S2:
			return 0
		diff = 0
		if sorted(S1) != sorted(S2):
			return False
		for i in range(len(S2)):
			if S1[i] != S2[i]:
				diff += 1
			if diff > 2:
				return False
		return True


from collections import Counter

class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return False
		if len(S1) == len(S2):
			if Counter(S1) == Counter(S2):
				return True
			else:
				return False
		else:
			return False


class Solution:

	def metaStrings(self, S1, S2):
		freq = [0] * 26
		if len(S1) != len(S2):
			return False
		for i in range(0, len(S1)):
			freq[ord(S1[i]) - ord('a')] += 1
			freq[ord(S2[i]) - ord('a')] -= 1
		for i in range(26):
			if freq[i] != 0:
				return False
		count = 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				count += 1
		return count == 2
x = Solution()
s1 = 'geeks'
s2 = 'keegs'
x.metaStrings(s1, s2)


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return False
		else:
			k = sorted(S1)
			l = sorted(S2)
			if k == l:
				return True
			else:
				return False


class Solution:

	def metaStrings(self, S1, S2):
		freq = [0] * 26
		if len(S1) != len(S2):
			return 0
		for i in range(len(S1)):
			freq[ord(S1[i]) - ord('a')] += 1
			freq[ord(S2[i]) - ord('a')] -= 1
		for i in range(26):
			if freq[i] != 0:
				return 0
		cnt = 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				cnt += 1
		return cnt == 2


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return False
		(diff1, diff2) = (-1, -1)
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				if diff1 == -1:
					diff1 = i
				elif diff2 == -1:
					diff2 = i
				else:
					return False
		if diff1 != -1 and diff2 != -1:
			if S1[diff1] == S2[diff2]:
				return True
		return False


class Solution:

	def metaStrings(self, s1, s2):
		if sorted(s1) != sorted(s2):
			return 0
		c = 0
		for i in range(len(s1)):
			if s1[i] != s2[i]:
				c += 1
		if c == 0:
			return 0
		return 1


class Solution:

	def metaStrings(self, S1, S2):
		S1 = list(S1)
		S2 = list(S2)
		if len(S1) != len(S2):
			return 0
		n = len(S1)
		i = 0
		j = 0
		while i < n - 1 and j < n:
			if S1[i] == S2[i]:
				i += 1
				j = i + 1
			else:
				if S1[j] == S2[i] and S1[j] != S2[j]:
					(S2[j], S2[i]) = (S2[i], S2[j])
					break
				j += 1
		else:
			return 0
		if S1 == S2:
			return 1
		return 0


class Solution:

	def metaStrings(self, s1, s2):
		if len(s1) != len(s2):
			return 0
		mismatch = 0
		for i in range(0, len(s1)):
			if s1[i] not in s2 or s2[i] not in s1:
				return 0
			elif s1[i] != s2[i]:
				mismatch += 1
		if mismatch == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2 or len(S1) != len(S2):
			return 0
		for i in range(len(S1)):
			a = S1[i]
			b = S2[i]
			if a != b and a in S2 and (b in S1):
				S1 = S1.replace(a, b)
				S2 = S2.replace(a, b)
				k = 1 if S1 == S2 else 0
				return k
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		n1 = len(S1)
		n2 = len(S2)
		if n1 != n2 or S1 == S2:
			return 0
		res = []
		counter = 0
		for i in range(n1):
			if S1[i] != S2[i]:
				res.append(S1[i])
				res.append(S2[i])
				counter += 1
		if counter == 2 and len(set(res)) == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		l1 = list(S1)
		l2 = list(S2)
		cnt = 0
		k = -1
		j = -1
		for i in range(len(S1)):
			if l1[i] != l2[i]:
				if cnt == 1:
					j = i
					break
				else:
					k = i
					cnt = 1
		if j == -1 or k == -1:
			return 0
		temp = l1[j]
		l1[j] = l1[k]
		l1[k] = temp
		if l1 == l2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return False
		else:
			n1 = sorted(S1)
			n2 = sorted(S2)
			if n1 == n2:
				return True
			else:
				return False


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return 0
		else:
			l1 = list(S1)
			l2 = list(S2)
			l1.sort()
			l2.sort()
			if l1 == l2:
				return 1
			else:
				return 0


class Solution:

	def metaStrings(self, S1, S2):
		ct = 0
		ans = []
		if S1 == S2:
			return 0
		if set(S1) != set(S2):
			return False
		if len(S1) != len(S2):
			return False
		for i in range(len(S1)):
			if S1[i] == S2[i]:
				pass
			else:
				ct += 1
		if ct == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		a = []
		pos = []
		n = 0
		for i in range(len(S2)):
			if S1[i] != S2[i]:
				a.append(S1[i])
				pos.append(i)
				n += 1
			if n == 2:
				break
		if n != 2:
			return 0
		S1 = list(S1)
		S2 = list(S2)
		S1[pos[0]] = a[1]
		S1[pos[1]] = a[0]
		if S1 == S2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return False
		j = 0
		diff = 0
		for i in S1:
			if i != S2[j]:
				diff += 1
			j += 1
		if diff == 2 and set(S1) == set(S2):
			return True
		return False


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return False
		if len(S1) != len(S2):
			return False
		if set(S1) != set(S2):
			return False
		n = len(S1)
		c = 0
		for i in range(n):
			if S1[i] != S2[i]:
				c += 1
		if c == 2:
			return True
		else:
			return False


class Solution:

	def metaStrings(self, S1, S2):
		(temp1, temp2) = (0, 0)
		flag = False
		count = 0
		if len(S1) != len(S2):
			return False
		for val1 in range(len(S1)):
			if S1[val1] != S2[val1] and flag == False:
				temp1 = S2[val1]
				temp2 = S1[val1]
				flag = True
			elif S1[val1] != S2[val1] and flag == True:
				if temp1 == S1[val1] and temp2 == S2[val1]:
					flag = 'invalid'
				else:
					return False
			elif S1[val1] == S2[val1]:
				count += 1
			elif S1[val1] != S2[val1] and flag == 'invalid':
				return False
		if count == len(S1):
			return False
		if flag == 'invalid':
			return True


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return 0
		prev_first = None
		prev_second = None
		swaps = 0
		n = len(S1)
		flag = False
		for i in range(n):
			if not flag and S1[i] != S2[i]:
				prev_first = S1[i]
				prev_second = S2[i]
				flag = True
			elif flag and S1[i] != S2[i]:
				if S1[i] == prev_second and S2[i] == prev_first:
					swaps += 1
				else:
					return 0
		if swaps == 0:
			return 0
		return 1


class Solution:

	def metaStrings(self, S1, S2):
		c = 0
		if S1 == S2 or set(S1) != set(S2) or len(S1) != len(S2):
			return 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				c += 1
		if c == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		n = len(S1)
		l = sorted(S1)
		p = sorted(S2)
		if l != p:
			return False
		c = 0
		for i in range(n):
			if S1[i] != S2[i]:
				c += 1
		return c == 2


class Solution:

	def metaStrings(self, S1, S2):
		ls1 = list(str(S1))
		ls2 = list(str(S2))
		count = 0
		for (i, j) in zip(ls1, ls2):
			if i != j:
				count = count + 1
		ls1.sort()
		ls2.sort()
		for (i, j) in zip(ls1, ls2):
			if i != j:
				return 0
		if count == 2:
			return 1
		if count == 0:
			return 0
		if count != 2:
			return 0
		return 0


from collections import defaultdict

class Solution:

	def metaStrings(self, S1, S2):
		if sorted(S1) != sorted(S2):
			return 0
		if S1 == S2:
			return 0
		count = 0
		(mp, mp1) = (defaultdict(list), defaultdict(list))
		for i in range(len(S1)):
			mp[S1[i]].append(i)
		for i in range(len(S2)):
			mp1[S2[i]].append(i)
		for (i, v) in mp.items():
			if v != mp1[i]:
				count += 1
		if count == 2:
			return 1
		else:
			return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return False
		c = 0
		a = b = -1
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				c += 1
				if c > 2:
					return False
				elif c == 1:
					a = S1[i]
					b = S2[i]
				elif c == 2 and (a != S2[i] or b != S1[i]):
					return False
		if c == 0 or c == 1:
			return False
		return True


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return 0
		n1 = len(S1)
		n2 = len(S2)
		if n1 != n2:
			return 0
		count = 0
		index = []
		for i in range(n1):
			if S1[i] != S2[i]:
				count += 1
				index.append(i)
		if count == 2 and S1[index[0]] == S2[index[1]] and (S1[index[1]] == S2[index[0]]):
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return 0
		elif sorted(S1) == sorted(S2):
			return 1


class Solution:

	def metaStrings(self, S1, S2):
		p = ''
		q = ''
		i = 0
		ct = 0
		if len(S1) != len(S2):
			return 0
		while i < len(S1):
			if S1[i] != S2[i]:
				ct += 1
				if ct == 1:
					p = S1[i]
					q = S2[i]
				elif ct == 2:
					if S1[i] == q and S2[i] == p:
						return 1
					else:
						return 0
			i += 1
			if ct > 2:
				return 0


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return 0
		swapping = False
		swapping_c = None
		swapped = False
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				if swapped:
					return 0
				if swapping:
					if swapping_c == S2[i]:
						swapped = True
					else:
						return 0
				else:
					swapping = True
					swapping_c = S1[i]
		return int(swapped)


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2):
			return False
		index = []
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				index.append(i)
			if len(index) > 2:
				return False
		if len(index) != 2:
			return False
		return S1[index[0]] == S2[index[1]] and S1[index[1]] == S2[index[0]]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input().strip()
		S2 = input().strip()
		obj = Solution()
		if obj.metaStrings(S1, S2):
			print(1)
		else:
			print(0)


import re

class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) != len(S2) or len(S1) < 2:
			return False
		l = ''
		m = ''
		change = 0
		for i in range(0, len(S1)):
			if S1[i] != S2[i]:
				if not change:
					change = 1
					l = S1[i]
					m = S2[i]
				else:
					if not l and (not m):
						return False
					if S1[i] != m or S2[i] != l:
						return False
					l = ''
					m = ''
		if l == '' and m == '' and change:
			return True
		else:
			return False
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input().strip()
		S2 = input().strip()
		obj = Solution()
		if obj.metaStrings(S1, S2):
			print(1)
		else:
			print(0)


class Solution:

	def metaStrings(self, S1, S2):
		indices = []
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				indices.append(i)
		if len(indices) != 2:
			return False
		S1 = list(S1)
		(S1[indices[0]], S1[indices[1]]) = (S1[indices[1]], S1[indices[0]])
		S1 = ''.join(S1)
		if S1 != S2:
			return False
		return True
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input().strip()
		S2 = input().strip()
		obj = Solution()
		if obj.metaStrings(S1, S2):
			print(1)
		else:
			print(0)


class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2 or len(S1) != len(S2):
			return False
		count = 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				count += 1
		if count == 2:
			return True
		return False
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input().strip()
		S2 = input().strip()
		obj = Solution()
		if obj.metaStrings(S1, S2):
			print(1)
		else:
			print(0)


class Solution:

	def metaStrings(self, S1, S2):
		count = -1
		S1_output = []
		if S1 == S2 or len(S1) != len(S2):
			return 0
		for i in range(0, len(S2)):
			S1_output.append(S1[i])
			if S1[i] != S2[i]:
				if count == -1:
					count = i
				else:
					temp = S1[i]
					S1_output[i] = S1_output[count]
					S1_output[count] = temp
		S1_output_string = ''.join(S1_output)
		if S1_output_string == S2:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input().strip()
		S2 = input().strip()
		obj = Solution()
		if obj.metaStrings(S1, S2):
			print(1)
		else:
			print(0)


class Solution:

	def metaStrings(self, S1, S2):
		if len(S1) == len(S2) and S1 != S2:
			cnt = 0
			for i in range(0, len(S1)):
				if S1[i] == S2[i]:
					continue
				else:
					cnt += 1
			if cnt == 2:
				return True
			else:
				return False
		else:
			return False


class Solution:

	def metaStrings(self, str1, str2):
		if len(str1) != len(str2):
			return False
		if str1 == str2:
			return False
		n = len(str1)
		first = -1
		second = -1
		for i in range(n):
			if str1[i] != str2[i]:
				if first == -1:
					first = i
				elif second == -1:
					second = i
				else:
					return False
		if second == -1:
			return False
		if str1[first] == str2[second] and str1[second] == str2[first]:
			return True
		return False


from collections import defaultdict

class Solution:

	def metaStrings(self, S1, S2):
		if S1 == S2:
			return 0
		count = 0
		d = defaultdict(int)
		for i in S1:
			d[i] += 1
		for i in S2:
			d[i] -= 1
		for i in d:
			if d[i] != 0:
				return 0
		for i in range(len(S1)):
			if S1[i] != S2[i]:
				count += 1
		if count == 2:
			return 1
		return 0


class Solution:

	def metaStrings(self, S1, S2):
		res = 0
		for (a, b) in zip(S1, S2):
			if a != b:
				res += 1
		return res == 2


class Solution:

	def metaStrings(self, s1, s2):
		if len(s1) != len(s2):
			return False
		n = len(s1)
		c = 0
		ind1 = []
		ind2 = []
		for i in range(n):
			if s1[i] != s2[i]:
				c += 1
				ind1.append(s1[i])
				ind2.append(s2[i])
		if c == 2 and ind1[0] == ind2[1] and (ind1[1] == ind2[0]):
			return True
		else:
			return False