COMPSTR - Compare The Strings

no tags 

Your company is writing a spell-checker system, and you have been tasked with writing a function to determine how closely two words resemble each other. The algorithm you are to use, albeit not a very good one, is to compare the two words character by character, and count how many times the characters in a given position are the same. For instance, the words "TICK" and "TOCK" have a score of 3, since three characters (T, C, K) are the same. Similarly, "CAT" and "DOG" score 0, since no letters match.

You are given strings a and b and are to find an integer indicating the score (as defined above) of how closely the two match.

Input

First line contains an integer T <= 100 - the number of testcases. Following each of T lines contains two space separated strings a and b. Both a and b will have length between 1 and 50 (inclusive) and will contain only 'A'-'Z' characters.

Output

For each testcase, output a single integer - the score of closeness of two strings.

Example

Input:
3
TICK TOCK
CAT DOG
APPLE APPLES

Output: 3
0
5

NOTE: In case the two strings are of different lengths, just compare until the end of shorter one.


hide comments
Karl-Aksel Puulmann: 2011-02-07 16:30:08

This would make an okay code-gulf.


Added by:Ankul Garg
Date:2011-02-05
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem