Under construction

Still being built. Things may change

Oulipo

Interview

Time limit1sMemory limit128 MB

Summary
Count overlapping occurrences of a pattern W in a text T over uppercase letters for each test case.
Level

Medium4 of 10

Topics
String matching, String
Solved
No attempts yet

Problem

The French writer Georges Perec (1936-1982) wrote a whole novel, La disparition, without ever using the letter 'e'. He belonged to the Oulipo group. A passage from the book:

Tout avait l’air normal, mais tout s’affirmait faux. Tout avait l’air normal, d’abord, puis surgissait l’inhumain, l’affolant. Il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : sur son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…

Perec would have scored high, or rather low, in the contest below. Entrants write a text on a given subject while making one given word appear as few times as possible. The jury needs a program that counts those appearances so the entrants can be ranked. Entrants often hand in very long texts with no meaning at all. A run of 500,000 consecutive 'T's is not unusual, and they never write spaces.

So we have to count quickly how often one string occurs inside another. Over the alphabet {'A', 'B', 'C', …, 'Z'} you are given a word WW and a text TT. Count how many times WW occurs in TT. Every character of WW must match consecutive characters of TT exactly. Occurrences may overlap.

Input

The first line contains the number of test cases. Each test case has this format:

  • One line with the word WW, a string over {'A', 'B', 'C', …, 'Z'}, with 1≤∣W∣≤1041 \le |W| \le 10^4. Here ∣W∣|W| is the length of WW.
  • One line with the text TT, a string over the same alphabet, with ∣W∣≤∣T∣≤106|W| \le |T| \le 10^6.

Output

For each test case, print the number of occurrences of WW in TT on a line of its own.

Examples1

  1. Example 1

    Input
    3
    BAPC
    BAPC
    AZA
    AZAZAZA
    VERDI
    AVERDXIVYERDIAN
    
    Expected output
    1
    3
    0