for _ in range(int(input())):
s1=list(dict.fromkeys(list(input())))
s2=list(dict.fromkeys(list(input())))
count=0
for i in range(len(s1)):
if s1[i] in s2:
count+=1
print(count)
@knight_nikhil You don’t need to use dictionaries to solve this problem. Refer to the following code:
def compute_total_jewels_present(jewel_stones, mined_stones):
jewel_count = 0
for stone in mined_stones:
if stone in jewel_stones:
jewel_count += 1
return jewel_count
def main():
for test_case in range(int(input())):
jewel_stones = input()
mined_stones = input()
print(compute_total_jewels_present(jewel_stones, mined_stones))
if __name__ == "__main__":
main()