Problem : Variable Pattern Search


March 25, 2007

STATEMENT

Given a string P composed of upper and lower case letters, its neighbours consist of all strings of the form σ(P) where σ is a permutation which permutes the upper case letters (A-Z) among themselves and fixes the lower case letters (a-z).

For example, the neighbours of aAb include aAb, aBb, aXb, etc., and the neighbours of aAAbB include aBBbA, aXXbZ, etc., but not aXXbX.

Given a pattern P and a text T your job is to find the 0-based starting points of all occurrences of neighbours of P when viewed as sub-words of T.

INPUT

The input file will contain several test cases. The first line contains an integer t, the number of test-cases. The succeeding lines contain the test-cases.

Input Format:

Each test-case comprises the following:


Line 1: p , t: The length of P and T respectively
Line 2: P a string comprising of upper and lower case letters
Line 3: T a string comprising of upper and lower case letters

OUTPUT

The output should comprise the solutions to all the test cases, in the order of the test cases in the input. There should NOT be any blank line in the output.

Output Format:

The 0-based starting points of all neighbours of P in T, one per each line.

POINTS and CONSTRAINTS

Total points: 100

Easy Set (40 points) : 1 p 100 , p t 100000
Hard set (60 points) : 1 t 1000000 , p t

Time Limit: 3 seconds
Memory Limit: 128 MB (Stack memory: 8MB)

SAMPLE INPUT

2
2 4
aA
aAbB
3 9
aBb
aAbbaBbCb

SAMPLE OUTPUT

0
0
4

CPU Timelimit: 3 seconds
Memory limit: 128M
Grading style: opc
Resource CMI Online Programming Contest 2007
Register Now

Running Contests

Search the archive: