Given a string s consisting of uppercase and lowercase alphabetic characters. Return the  number of distinct substrings of size 2 that appear in s as contiguous substrings.
Example
Input :
s = "ABCAB"
Output :
3
Explanation:  For "ABCAB", the 
three distinct substrings of size 
2 are "AB", "BC" and "CA". 
Example
Input :
s = "XYZ"
Output :
2
Explanation: For "XYZ", the 
two distinct substrings of size 2 are
"XY" and "YZ".
Your Task :
You don't need to read input or print anything. You have to complete the function fun() which takes the string s as input parameter and returns the number of distinct contiguous substring of size 2.
Expected Time Complexity : O(|s|)
Expected Auxilliary Space : O(|s|)
Constraints:
1<=|s|<=100
|s| denotes the length of the string s.

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(|s|)

Starter code:
#User function Template for python3

class Solution:

    def fun(self, s):
        # code here

Solutions:
class Solution:

	def fun(self, s):
		d = {}
		for i in range(len(s) - 1):
			if (s[i] and s[i + 1]) not in d:
				d[s[i], s[i + 1]] = 1
			else:
				d[s[i], s[i + 1]] += 1
		return len(d)


from collections import defaultdict

class Solution:

	def fun(self, s):
		hmap = defaultdict(int)
		for i in range(0, len(s) - 1):
			if s[i] and s[i + 1] not in hmap:
				hmap[s[i], s[i + 1]] = 1
			else:
				hmap[s[i], s[i + 1]] += 1
		return len(hmap)


class Solution:

	def fun(self, s):
		us = set()
		for i in range(1, len(s)):
			us.add(s[i - 1] + s[i])
		return len(us)


class Solution:

	def fun(self, s):
		dict = {}
		count = 0
		for i in range(len(s) - 1):
			sub = s[i] + s[i + 1]
			if dict.get(sub) == None:
				count += 1
				dict.update({sub: 1})
		return count


class Solution:

	def fun(self, s):
		hash = set()
		for i in range(0, len(s) - 1):
			hash.add(s[i:i + 2])
		return len(hash)


class Solution:

	def fun(self, s):
		res = set()
		for i in range(len(s) - 1):
			t = s[i:i + 2]
			res.add(t)
		return len(res)


class Solution:

	def fun(self, s):
		hmap = {}
		count = 0
		for i in range(len(s) - 1):
			temp = s[i] + s[i + 1]
			if temp in hmap:
				hmap[temp] += 1
			else:
				hmap[temp] = 1
		return len(hmap)


class Solution:

	def fun(self, s):
		l = []
		for i in range(len(s) - 2 + 1):
			if s[i:i + 2] not in l:
				l.append(s[i:i + 2])
		return len(l)


class Solution:

	def fun(self, s):
		d = {}
		if len(s) == 2:
			return 1
		elif len(s) < 2:
			return 0
		else:
			for i in range(len(s) - 1):
				a = s[i:i + 2]
				if a not in d:
					d[a] = 1
			return len(d)


class Solution:

	def fun(self, s):
		b = []
		for i in range(len(s) - 1):
			b.append(s[i:i + 2])
		c = set(b)
		d = len(c)
		return d


class Solution:

	def fun(self, s):
		substr_set = set()
		for i in range(len(s) - 1):
			if s[i:i + 2] not in substr_set:
				substr_set.add(s[i:i + 2])
		return len(substr_set)


class Solution:

	def fun(self, s):
		n = len(s)
		st = set()
		for i in range(n - 1):
			string = s[i:i + 2]
			st.add(string)
		return len(st)


class Solution:

	def fun(self, s):
		return len(set([s[i:i + 2] for i in range(len(s) - 1)]))


class Solution:

	def fun(self, s):
		new_set = set()
		for a in range(0, len(s)):
			if a == len(s) - 1:
				B = s[a - 1] + s[a]
			else:
				B = s[a] + s[a + 1]
				new_set.add(B)
		return len(new_set)


class Solution:

	def fun(self, s):
		res = []
		i = 0
		while i < len(s) - 1:
			if [s[i].lower(), s[i + 1].lower()] not in res:
				res.append([s[i].lower(), s[i + 1].lower()])
			i += 1
		return len(res)


class Solution:

	def fun(self, s):
		A = []
		for i in range(len(s) - 1):
			X = s[i:i + 2]
			if X not in A and X[-1] not in A:
				A.append(X)
		return len(A)


class Solution:

	def fun(self, s):
		ans = 0
		li = []
		for i in range(len(s)):
			if s[i:i + 2] != s[i + 1:i + 3] and s[i:i + 2] not in li:
				li.append(s[i:i + 2])
				ans += 1
		return ans - 1


class Solution:

	def fun(self, s):
		l = []
		c = 0
		for i in range(len(s)):
			if s[i:i + 2] != s[i + 1:i + 3] and s[i:i + 2] not in l:
				c += 1
				l.append(s[i:i + 2])
		return c - 1


class Solution:

	def fun(self, s):
		l = []
		st = ''
		for i in range(len(s) - 1):
			st = s[i] + s[i + 1]
			l.append(st)
		return len(set(l))


class Solution:

	def fun(self, s):
		i = 0
		l = []
		while i < len(s) - 1:
			if s[i:i + 2] not in l:
				l.append(s[i:i + 2])
			i += 1
		return len(l)


class Solution:

	def fun(self, s):
		res = []
		n = len(s)
		for i in range(n - 1):
			temp = s[i] + s[i + 1]
			if temp not in res:
				res.append(temp)
		return len(res)


class Solution:

	def fun(self, s):
		n = len(s)
		m = {}
		for i in range(n - 1):
			t = s[i] + s[i + 1]
			m[t] = 1
		return len(m)


class Solution:

	def fun(self, s):
		list1 = []
		for i in range(1, len(s)):
			if s[i - 1:i + 1] not in list1:
				list1.append(s[i - 1:i + 1])
			else:
				pass
		return len(list1)


class Solution:

	def fun(self, s):
		res = 0
		seen = set()
		for i in range(len(s) - 1):
			if s[i:i + 2] not in seen:
				res += 1
				seen.add(s[i:i + 2])
		return res


class Solution:

	def fun(self, s):
		a = 0
		x = []
		while a < len(s) - 1:
			c = s[a:a + 2]
			if c not in x:
				x.append(c)
			a += 1
		return len(x)


class Solution:

	def fun(self, s):
		k = {}
		for i in range(len(s) - 1):
			tmp = s[i:i + 2]
			if tmp not in k.keys():
				k[tmp] = 1
			else:
				k[tmp] += 1
		return len(k)


class Solution:

	def fun(self, s):
		hashset = set()
		(l, r) = (0, 1)
		while r < len(s):
			sub = s[l] + s[r]
			hashset.add(sub)
			l += 1
			r += 1
		return len(hashset)


class Solution:

	def fun(self, s):
		d = []
		for i in range(0, len(s) - 1):
			x = s[i] + s[i + 1]
			if x in d:
				continue
			else:
				d.append(x)
		return len(d)


class Solution:

	def fun(self, s):
		s = list(s)
		count = 0
		dset = []
		for i in range(len(s) - 1):
			a = str(s[i] + s[i + 1])
			if a in dset:
				continue
			else:
				dset.append(a)
				count += 1
		return count


class Solution:

	def fun(self, s):
		s = list(s)
		count = 0
		d = {}
		for i in range(len(s) - 1):
			a = str(s[i] + s[i + 1])
			if a in d.keys():
				continue
			else:
				d[a] = 1
				count += 1
		return count


class Solution:

	def fun(self, s):
		S = set()
		for i in range(len(s) - 1):
			S.add(s[i:i + 2])
		return len(S)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.fun(s))


class Solution:

	def fun(self, s):
		n = len(s)
		h = {}
		if n > 1:
			i = 0
			j = i + 1
			c = 0
			while j < n:
				x = s[i] + s[j]
				if x not in h:
					h[x] = 1
					c = c + 1
				i = i + 1
				j = j + 1
			return c
		else:
			return -1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.fun(s))


class Solution:

	def fun(self, s):
		substr = []
		for i in range(len(s) - 1):
			substr.append(s[i:i + 2])
		substr = list(set(substr))
		return len(substr)


class Solution:

	def fun(self, s):
		d = set()
		for i in range(len(s) - 1):
			st = s[i] + s[i + 1]
			d.add(st)
		return len(d)


class Solution:

	def fun(self, s):
		n = len(s)
		m = {}
		m[s[0:2]] = 1
		for i in range(1, n):
			if i + 1 < n:
				if s[i:i + 2] in m:
					m[s[i:i + 2]] += 1
				else:
					m[s[i:i + 2]] = 1
		return len(m)


from collections import defaultdict

class Solution:

	def fun(self, s):
		d = defaultdict(int)
		for i in range(len(s) - 1):
			temp = ''
			temp = s[i] + s[i + 1]
			d[temp] += 1
		return len(d.keys())


class Solution:

	def fun(self, s):
		dict_ = {}
		for i in range(len(s) - 1):
			ss = s[i:i + 2]
			if ss not in dict_:
				dict_[ss] = 1
			else:
				dict_[ss] += 1
		return len(dict_)


class Solution:

	def fun(self, s):
		i = -1
		j = -1
		count = 0
		st = ''
		dict = {}
		for i in range(len(s) - 1):
			st = s[i:i + 2]
			sorted(st)
			if st not in dict:
				dict[st] = 1
				count += 1
		return count


class Solution:

	def fun(self, s):
		res = []
		i = 0
		j = 2
		n = len(s)
		while j <= n:
			res.append(s[i:j])
			j += 1
			i += 1
		res.sort()
		l = len(res)
		i = 0
		r = [res[0]]
		while i < l:
			if res[i] != r[-1]:
				r.append(res[i])
			i += 1
		return len(r)


class Solution:

	def fun(self, s):
		ans = []
		for i in range(len(s) - 1):
			a = s[i] + s[i + 1]
			ans.append(a)
		return len(set(ans))


class Solution:

	def fun(self, s):
		i = 0
		j = 1
		ss = set()
		while j < len(s):
			ss.add(s[i] + s[j])
			i += 1
			j += 1
		return len(ss)


from collections import defaultdict

class Solution:

	def fun(self, s):
		c = 0
		d = defaultdict(lambda : 0)
		for i in range(0, len(s) - 1):
			x = s[i:i + 2]
			d[x] += 1
			if d[x] == 1:
				c += 1
		return c


class Solution:

	def fun(self, s):
		dic = {}
		for i in range(len(s) - 1):
			try:
				dic[s[i:i + 2]] += 1
			except:
				dic[s[i:i + 2]] = 1
		return len(dic)


class Solution:

	def fun(self, s):
		h_map = {}
		n = len(s)
		for i in range(len(s) - 1):
			if s[i] + s[i + 1] in h_map:
				h_map[s[i] + s[i + 1]] += 1
			else:
				h_map[s[i] + s[i + 1]] = 1
		return len(h_map)


class Solution:

	def fun(self, s):
		arr = []
		for i in range(len(s) - 1):
			p = ''
			p = s[i] + s[i + 1]
			arr.append(p)
		return len(set(arr))


class Solution:

	def fun(self, s):
		substrings = [s[i] + s[i + 1] for i in range(len(s) - 1)]
		return len(list(set(substrings)))


class Solution:

	def fun(self, s):
		c = 0
		ss = set()
		for i in range(0, len(s)):
			for j in range(i + 1, len(s) + 1):
				if len(s[i:j]) == 2 and s[i:j] not in ss:
					ss.add(s[i:j])
		return len(ss)


class Solution:

	def fun(self, s):
		dict1 = {}
		for i in range(0, len(s)):
			if s[i:i + 2] not in dict1:
				dict1[s[i:i + 2]] = 1
		count = 0
		result_str = ''
		for i in dict1:
			if len(i) == 2:
				result_str += i + ' '
				count += 1
		return count


class Solution:

	def fun(self, s):
		l = []
		for x in range(len(s) - 1):
			a = s[x] + s[x + 1]
			l.append(a)
		return len(set(l))


class Solution:

	def fun(self, s):
		substring = []
		index = 1
		pre_index = 0
		while index < len(s):
			new_str = str(s[pre_index]) + str(s[index])
			if new_str not in substring:
				substring.append(new_str)
			index += 1
			pre_index += 1
		return len(substring)


class Solution:

	def fun(self, s):
		sp = []
		for i in range(0, len(s) - 1):
			u = s[i:i + 2]
			sp.append(u)
		ans = int(len(list(set(sp))))
		return ans


class Solution:

	def fun(self, s):
		t = []
		n = len(s)
		for i in range(0, n - 1):
			u = s[i:i + 2]
			t.append(u)
		ans = set(t)
		return len(ans)


import math

class Solution:

	def fun(self, s):
		l = []
		for i in range(len(s) - 1):
			a = ''
			a = s[i] + s[i + 1]
			l.append(a)
		return len(set(l))


class Solution:

	def fun(self, s):
		n = len(s)
		tmp_dict = {}
		count = 0
		for i in range(n - 1):
			curr_s = s[i:i + 2]
			if not tmp_dict.get(curr_s):
				count += 1
				tmp_dict[curr_s] = 1
		return count


class Solution:

	def fun(self, s):
		substr_set = set()
		for (i, letter) in enumerate(s):
			if i < len(s) - 1:
				substr_set.add(s[i:i + 2])
		return len(substr_set)


class Solution:

	def fun(self, s):
		a = []
		n = len(s)
		for i in range(0, n - 1):
			j = i + 1
			if s[i] + s[j] not in a:
				a.append(s[i] + s[j])
		return len(a)


class Solution:

	def fun(self, s):
		distinct = set()
		length = len(s)
		for i in range(length - 1):
			distinct.add(s[i:i + 2])
		return len(distinct)


class Solution:

	def fun(self, s):
		(n, x) = (len(s), 0)
		st = set()
		for i in range(n - 1):
			snew = s[i:i + 2]
			st.add(snew)
		return len(st)


class Solution:

	def fun(self, s):
		lst = []
		i = 0
		j = 1
		while j != len(s):
			x = s[i:j + 1]
			if x not in lst:
				lst.append(x)
			i += 1
			j += 1
		return len(lst)


class Solution:

	def fun(self, s):
		hashset = set()
		for i in range(len(s) - 1):
			char = s[i:i + 2]
			hashset.add(char)
		return len(hashset)


class Solution:

	def fun(self, s):
		ans = 0
		arr = set()
		for i in range(len(s) - 1):
			if s[i] + s[i + 1] not in arr:
				ans += 1
				arr.add(s[i] + s[i + 1])
		return ans


class Solution:

	def fun(self, s):
		d = {}
		for i in range(len(s) - 1):
			if s[i:i + 2] not in d:
				d[s[i:i + 2]] = 1
			else:
				d[s[i:i + 2]] = d[s[i:i + 2]] + 1
		c = 0
		for (key, val) in d.items():
			c += 1
		return c


class Solution:

	def fun(self, s):
		ans = []
		p = set()
		for i in range(1, len(s)):
			x = ''.join(s[i - 1:i + 1])
			if x not in p:
				ans.append(x)
				p.add(x)
		return len(ans)