404397: GYM101498 B Longest Prefix
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
B. Longest Prefixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
You are given two strings a and b. Find the longest common prefix between them after performing zero or more operation on string b. In each operation you can swap any two letters.
InputThe first line of the input contains an integer T (1 ≤ T ≤ 500), where T is the number of the test cases.
Each case has one line that contains two space separated strings a and b.
All strings are non-empty consisting of lowercase English letters only. The length of each of these strings does not exceed 105 characters.
OutputPrint T lines, each line contains a single integer that represents the length of the longest common prefix between a and b.
ExampleInput3Output
hello hey
here there
you me
2
4
0