This page is still under construction.

Parts of this page are still being built. What you see may change.

Mutation

Time limit2sMemory limit256 MB

Summary
Count overlapping occurrences in a DNA string of a marker and all strings formed by reversing one substring of the marker.
Level

Medium6 of 10

Topics
String matching, Hash map
Solved
No attempts yet

Problem

The DNA of a person is written as one long string over the letters A, C, G, and T.

Some diseases are known to be linked to a contiguous substring of that string. If the DNA contains a particular string as a substring, the chance of having the disease is high. Such a string is called a marker.

Markers mutate, so looking for the marker itself is not enough to find the marker linked to a disease.

A marker mutates like this.

  • Split the marker into three parts, left to right. The first part and the third part are allowed to be empty.
  • Reverse the middle part.

For the marker AGGT there are six possible results: GAGT, GGAT, TGGA, AGGT, ATGG, AGTG.

Given the DNA of a person and a marker, write a program that counts how many times the marker and its mutations appear in the DNA.

Occurrences are allowed to overlap. For example, if the DNA is ATGGAT and the marker is AGGT, the answer is 3, because ATGG, TGGA, and GGAT each appear once.

Input

The first line contains the number of test cases TT.

Each test case takes three lines. The first line contains the length of the DNA string nn and the length of the marker mm, separated by a space (1≤n≤1,000,0001 \le n \le 1{,}000{,}000, 1≤m≤1001 \le m \le 100). The second line contains the DNA, and the third line contains the marker.

Both the DNA and the marker consist only of the letters A, C, G, and T.

Output

For each test case, print on its own line a single integer, the number of times the marker and its mutations appear in the DNA.

If neither the marker nor any of its mutations appears in the DNA, print 0.

Examples1

  1. Example 1

    Input
    2
    6 4
    ATGGAT
    AGGT
    6 4
    ATGGAT
    AGCT
    
    Expected output
    3
    0