Problem Statement:
Good guy Greg, the ninja, wants to break into a terrorist facility, he was able to retrieve a large string that contains the password of the back door of the facility.

Greg was also able to retrieve some information on the password, like the exact number of certain characters the password must hold.

Your job is to find the smallest substring that fits all the information of the password.


Input Format:
The first line of input contains an integer T, the number of test cases.

The first line of each test case is a non-empty string that has no more than 100000 lowercase latin letters.
The second line will have a positive integer N, the number of information he has, followed by N strings of the form XY where X is the frequency of the character Y in the password.


Output Format:
For each test case, print -1 if such substring doesn't exist, otherwise print the size of the smallest substring that fits all the information of the password.


Sample Input:
2 atwooj 3 2o 1w 1a bahosain 3 2a 1h 2o


Sample Output:
5 -1





Added by: Hasan0540
Added at: 2014-10-01 09:00:00 UTC
Time Limit: 2 seconds
Partial score: No
Source:Jordan Universities Training Contest #1