Equivalent Strings 2
Practice
5 (1 votes)
Algorithms
Open
Approved
Hard
Problem
56% Success 737 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

In this problem, 2 strings A and B of same length N are considered equivalent if following conditions are true for all 1 <= i, j <= N:

  1. (Ai != Aj) <=> (Bi != Bj)
  2. (Ai = Aj) <=> (Bi = Bj)

where Si denotes the i-th (1-based indexing) character of string S. It is easy to see that, if strings A and B are equivalent, strings B and C are equivalent, then strings A and C are also equivalent.

You are given 2 strings A and B of the same length N. You have to answer Q queries. Each query consists of 3 integers i, j, k, and for given query you are asked to check whether strings A[ i, i + k - 1] and B[ j, j + k - 1] are equivalent.

Input

The first line contains T - the number of test cases. Then T test cases follow.

Each test case consists of several lines.

  • The first line contains string A. The second line contains string B. They both have same length N.
  • The next line contains a positive integer Q - the number of queries you have to answer.
  • Then Q lines follow, each line contains 3 integers i, j, k with meaning described in the statement. It is guaranteed that 1 ≤ iN - k + 1; 1 ≤ jN - k + 1.

Output

For each query, print "yes" (without quotes) if substrings are equivalent and "no" otherwise. Print answer for every query in new line.

Constraints

  • Let SN be the sum of N over all T test cases, SQ be the sum of Q over all T test cases.
  • 1 ≤ SN, SQ ≤ 100000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
17 votes
Tags:
AlgorithmsDynamic ProgrammingOpenApprovedHard
Points:50
Tags:
GeometryDynamic Programming
Points:50
2 votes
Tags:
HardAlgorithmsApproved