아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

String Distance

시간 제한4초메모리 제한512 MB

요약
각 질의마다 A의 부분 문자열과 짧은 문자열 B 전체 사이의 편집 거리를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 문자열
정답자
아직 제출이 없습니다

문제

For two strings SS and TT, you can do the following operation an arbitrary number of times: Select a string SS or TT, insert or delete a character at any position. The distance between two strings SS and TT is defined as the minimum number of operations to make SS and TT equal.

You will be given two strings A\[1..n]A\[1..n] and B\[1..m]B\[1..m], and also qq queries.

In each query, you will be given two integers l_il\_i and r_ir\_i (1≤l_i≤r_i≤n1 \leq l\_i \leq r\_i \leq n). You need to find the distance between the continuous substring A\[l_i..r_i]A\[l\_i..r\_i] and the whole string BB.

입력

The first line contains a single integer TT (1≤T≤101 \leq T \leq 10), the number of test cases. For each test case:

The first line contains a string AA which consists of nn (1≤n≤100,0001 \leq n \leq 100\\,000) lower-case English letters.

The second line contains a string BB which consists of mm (1≤m≤201 \leq m \leq 20) lower-case English letters.

The third line contains a single integer qq (1≤q≤100,0001 \leq q \leq 100\\,000) denoting the number of queries.

Each of the following qq lines contains two integers l_il\_i and r_ir\_i (1≤l_i≤r_i≤n1 \leq l\_i \leq r\_i \leq n) describing a query.

출력

For each query, print a single line containing an integer denoting the answer.

예제1

  1. 예제 1

    입력
    1
    qaqaqwqaqaq
    qaqwqaq
    3
    1 7
    2 8
    3 9
    
    예상 출력
    4
    2
    0