Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not.  Her King requested for her help in mining precious stones, so she has told him which all stones are jewels and which are not. Given her description, your task is  to count the number of jewel stones. 

More formally, you're given a string J composed of latin characters where each character is a jewel. You're also given a string S composed of latin characters where each character is a mined stone. You have to find out how many characters of S are in J as well. 

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

First line contains an integer T denoting the number of test cases. Then follow T test cases. Each test case consists of two lines, each of which contains a string composed of English lower case and upper characters. First of these is the jewel string J and the second one is stone string S. You can assume that  1 ≤ T ≤ 100, 1 ≤ |J|, |S| ≤ 100

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

Output for each test case, a single integer, the number of jewels mined. 

----- Sample Input 1 ------ 
4
abc
abcdef
aA
abAZ
aaa
a
what
none
----- Sample Output 1 ------ 
3
2
1
0

Source: codechef | Difficulty: EASY
Tags: String algorithms

Data structures


Solutions:
for i in range(int(input())):
	s1 = input()
	s2 = input()
	c = 0
	for i in s2:
		if i in s1:
			c = c + 1
	print(c)


for _ in range(int(input())):
	a = input()
	b = input()
	n = [i for i in b if i in a]
	print(len(n))


for _ in range(int(input())):
	j = input()
	s = input()
	cnt = 0
	for i in s:
		if i in j:
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	j = input()
	s = input()
	count = 0
	for i in s:
		if i in j:
			count += 1
	print(count)


from collections import Counter
for i in range(int(input())):
	s = input()
	q = input()
	k = 0
	for i in q:
		if i in s:
			k += 1
	print(k)


t = int(input())
while t:
	count = 0
	j = input()
	s = input()
	for char in s:
		if char in j:
			count += 1
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	a = list(set(input()))
	b = input()
	count = 0
	for i in range(len(a)):
		for j in range(len(b)):
			if a[i] == b[j]:
				count += 1
	print(count)


q = int(input())
while q > 0:
	j = input()
	j = list(j)
	s = input()
	s = list(s)
	c = 0
	for i in s:
		if i in j:
			c = c + 1
	print(c)
	q = q - 1


for i in range(int(input())):
	S = input()
	J = input()
	count = 0
	for i in range(len(J)):
		agree = 0
		for j in range(len(S)):
			if S[j] == J[i] and S.count(S[j]) < 2:
				count += 1
			elif S[j] == J[i] and S.count(S[j]) > 1:
				agree += 1
				if agree == 1:
					count += 1
	print(count)


t = int(input())
for j in range(t):
	x = input()
	y = input()
	c = 0
	for i in y:
		if i in x:
			c += 1
	print(c)


for _ in range(int(input())):
	j = input()
	s = input()
	c = 0
	for ch in s:
		if ch in j:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	s = input()
	r = input()
	c = 0
	for i in range(len(r)):
		if r[i] in s:
			c = c + 1
	print(c)


for i in range(int(input())):
	s = list(input().strip())
	t = list(input().strip())
	m = {}
	s1 = set(s)
	s2 = list(s1)
	for j in s2:
		if j in m:
			m[j] += 1
		else:
			m[j] = 1
	c = 0
	for h in t:
		if h in m:
			c += 1
	print(c)


T = int(input())
for k in range(T):
	A = input()
	B = input()
	C = 0
	for i in B:
		for j in A:
			if i == j:
				C += 1
				break
	print(C)


for _ in range(int(input())):
	jewel = input()
	stone = input()
	countjewel = 0
	for item in stone:
		if item in jewel:
			countjewel += 1
	print(countjewel)


def func(s1, s2):
	count = 0
	for s in s2:
		if s in s1:
			count += 1
	return count
t = int(input())
while t > 0:
	s1 = input()
	s2 = input()
	count1 = func(s1, s2)
	print(count1)
	t = t - 1


t = int(input())
for i in range(t):
	j = input()
	s = input()
	j = list(j)
	s = list(s)
	c = 0
	for k in s:
		if k in j:
			c += 1
		else:
			c += 0
	print(c)


for i in range(int(input())):
	j = input()
	s = input()
	result = 0
	for i in s:
		if i in j:
			result += 1
	print(result)


for _ in range(int(input())):
	j = set(input())
	s = input()
	c = 0
	for i in s:
		if i in j:
			c += 1
	print(c)


t = int(input(''))
while t > 0:
	s = input('')
	l = input('')
	m = list(s)
	n = list(l)
	h = list()
	for i in n:
		if i in m:
			h.append(i)
	print(len(h))
	t = t - 1


t = int(input())
for i in range(t):
	j = input()
	s = input()
	c = 0
	for i in s:
		if i in j:
			c += 1
	print(c)


for i in range(int(input())):
	(s1, s2) = (input(), input())
	c = 0
	for j in range(len(s2)):
		for k in range(len(s1)):
			if s1[k] == s2[j]:
				c += 1
				break
	print(c)


for _ in range(int(input())):
	j = input()
	j = list(dict.fromkeys(list(j)))
	s = input()
	ans = 0
	for i in j:
		ans += s.count(i)
	print(ans)


for _ in range(int(input())):
	j = input()
	s = input()
	count = 0
	for c in s:
		if c in j:
			count += 1
		else:
			continue
	print(count)


for t in range(int(input())):
	J = set(input())
	S = list(input())
	gems = 0
	for i in J:
		gems += S.count(i)
	print(gems)


for i in range(int(input())):
	j = input()
	s = input()
	new = list(set(j))
	count = 0
	for i in range(len(new)):
		count = count + s.count(new[i])
	print(count)


for i in range(int(input())):
	j = input()
	s = input()
	count = 0
	for i in range(len(s)):
		if s[i] in j:
			count += 1
	print(count)


T = int(input())
for i in range(T):
	J = input()
	S = input()
	count = 0
	for stone in S:
		if stone in J:
			count += 1
	print(count)


for tc in range(int(input())):
	jew = set(input())
	mine = input()
	count = 0
	for ele in mine:
		if ele in jew:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	j = input()
	s = input()
	n_jewls = 0
	for x in range(len(s)):
		if s[x] in j:
			n_jewls += 1
	print(n_jewls)


for _ in range(int(input())):
	a = input()
	b = input()
	a = list(set(a))
	count = 0
	for i in b:
		if i in a:
			count += 1
	print(count)


def stones():
	J = input()
	S = input()
	c = 0
	for i in range(len(S)):
		for j in range(len(J)):
			if J[j] == S[i]:
				c += 1
				break
	print(c)
t = int(input())
for i in range(t):
	stones()


def count_jewels(jewels, stones):
	count = 0
	for s in stones:
		if s in jewels:
			count += 1
	return count
t = int(input())
for i in range(t):
	jewels = input().strip()
	stones = input().strip()
	jewel_count = count_jewels(jewels, stones)
	print(jewel_count)


def count_jewels(j, s):
	c = 0
	for x in s:
		if x in j:
			c += 1
	return c
t = int(input())
for i in range(t):
	j = input().strip()
	s = input().strip()
	print(count_jewels(j, s))


for t in range(int(input())):
	s1 = input()
	s2 = input()
	m = {}
	c = 0
	for i in s1:
		if i not in m:
			m[i] = 1
		else:
			m[i] = m[i] + 1
	for i in s2:
		if i in m:
			c = c + 1
			m[i] = m[i] - 1
	print(c)


n = int(input())
for k in range(n):
	a = set(input())
	b = list(input())
	c = 0
	for i in a:
		if i in b:
			c += b.count(i)
	print(c)


t = int(input())
for i in range(0, t):
	j = input()
	s = input()
	x = list(j)
	y = list(s)
	l = []
	for i in y:
		if i in x:
			l.append(i)
	print(len(l))


for _ in range(int(input())):
	j = input()
	s = input()
	j1 = set(j)
	s1 = list(s)
	c = 0
	for i in s1:
		if i in j1:
			c = c + 1
	print(c)


for _ in range(int(input())):
	s = input()
	cs = input()
	c = 0
	for ele in cs:
		if ele in s:
			c += 1
	print(c)


for _ in range(int(input())):
	s = input()
	s = list(set(s))
	st = input()
	cou = 0
	for i in s:
		cou += st.count(i)
	print(cou)


t = int(input())
for i in range(t):
	s = input()
	t = input()
	x = 0
	u = ''
	for char in s:
		if char not in u:
			u = u + char
	for i in range(len(u)):
		for j in range(len(t)):
			if u[i] == t[j]:
				x = x + 1
	print(x)


n = int(input())
for i in range(n):
	c = 0
	x = input()
	y = input()
	x = set(x)
	y = list(y)
	for i in x:
		if i in y:
			c += y.count(i)
	print(c)


for _ in range(int(input())):
	j = input()
	s = input()
	c = 0
	j_l = list(j)
	s_l = list(s)
	for x in s_l:
		if x in j_l:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	s = str(input())
	d = str(input())
	k = set(s)
	c = 0
	for j in d:
		if j in k:
			c = c + 1
	print(c)


for _ in range(int(input())):
	jw = input()
	st = input()
	dic = {}
	for i in st:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	c = 0
	for j in dic:
		if j in jw:
			c += dic[j]
	print(c)


t = int(input())
for k in range(t):
	A = input()
	B = input()
	c = 0
	for i in B:
		for j in A:
			if i == j:
				c += 1
				break
	print(c)


for i in range(int(input())):
	s = str(input())
	d = str(input())
	c = 0
	for i in range(len(d)):
		if d[i] in s:
			c += 1
	print(c)


T = int(input())
for x in range(T):
	j = list(input())
	s = list(input())
	k = 0
	for i in s:
		if i in j:
			k += 1
		else:
			continue
	print(k)


def test():
	j = input()
	s = input()
	cnt = 0
	for i in range(len(s)):
		for k in range(len(j)):
			if j[k] == s[i]:
				cnt += 1
				break
	print(cnt)
t = int(input())
for _ in range(t):
	test()


def hash(l):
	dict = {}
	n = len(l)
	for i in range(n):
		if l[i] in dict.keys():
			dict[l[i]] += 1
		else:
			dict[l[i]] = 1
	return dict
n = int(input())
for _ in range(n):
	s = input()
	s1 = input()
	s2 = s + s1
	count = 0
	dict = hash(s)
	dict1 = hash(s1)
	count = 0
	for i in dict1:
		if i in dict:
			count += dict1[i]
	print(count)


t = int(input())
while t:
	j = set(input())
	s = input()
	a = 0
	for c in s:
		if c in j:
			a += 1
	print(a)
	t -= 1


t = int(input())
for p in range(t):
	s = input()
	s1 = input()
	c = 0
	for i in s1:
		if i in s:
			c += 1
	print(c)


t = int(input())
while t > 0:
	j = input()
	s = input()
	size = len(s)
	count = 0
	for i in range(size):
		if s[i] in j:
			count = count + 1
	print(count)
	t = t - 1


try:
	for i in range(int(input())):
		j = input()
		m = input()
		count = 0
		for i in m:
			if i in j:
				count = count + 1
		if count == 0:
			print(0)
		else:
			print(count)
except:
	pass


t = int(input())
for i in range(t):
	j = input()
	s = input()
	y = [i for i in s if i in j]
	print(len(y))


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	count = 0
	for x in s2:
		if x in s1:
			count = count + 1
	print(count)


t = int(input())
for p in range(t):
	j = str(input())
	s = str(input())
	j = set(j)
	c = 0
	for i in s:
		if i in j:
			c = c + 1
	print(c)


for _ in range(int(input())):
	s = input()
	s1 = input()
	c = 0
	for i in s1:
		if i in s:
			c += 1
	print(c)


T = int(input())
for i in range(T):
	j = sorted(input())
	S = sorted(input())
	c = 0
	for k in S:
		if k in j:
			c += 1
		else:
			c += 0
	print(c)


for i in range(int(input())):
	J = input()
	S = input()
	c = 0
	for i in S:
		if i in J:
			c += 1
	print(c)


t = int(input())
for tc in range(t):
	s = input()
	j = input()
	c = 0
	for k in j:
		if k in s:
			c += 1
	print(c)