eolymp
bolt
Try our new interface for solving problems
Problems

Edit Distance Yet Again

Edit Distance Yet Again

Have you ever heard of the edit distance problem? Given two strings of lowercase English letters, you must determine the minimum number of operations needed to transform the first one into the second one. A single operation can be either:

  • inserting a character into the sequence, at any spot,
  • deleting any character from the sequence,
  • substituting a character with another one.

Everyone at our university loves this problem a lot - maybe a little bit too much - so we decided to create a problem which is easier! You are given two strings s = s1...sn, t = t1...tm and an integer k. Find out whether the edit distance between the strings is less than or equal to k. If so, you are also asked to provide any sequence of minimum possible number of operations to transform the first string into the second one.

Input

The first line contains the number of test cases z (1z100). The descriptions of the test cases follow.

The first line of each test case contains three integers n, m, k (1n, m106, 0k1000) - the lengths of the strings and the parameter from the problem description.

The second line contains a string of length n consisting of lowercase English letters - the string s from the problem description.

The third line contains a string of length m consisting of lowercase English letters - the string t from the problem description.

The total length of all strings in all test cases will not exceed 107.

Output

For each test case, if the edit distance is greater than k, output a single line containing the word "NO". Otherwise, the first line should contain the word "YES", and the next lines should describe the answer as follows:

In the second line output the minimum number r of operations required to transform s into t. In the next r lines output the operations, one per line.

  • To insert a lowercase English character c into a sequence of size w at the position p (1pw + 1), print INSERT p c.
  • To delete a character from a sequence of size w from the position p (1pw), print DELETE p.
  • To substitute a character in a sequence of size w from the position p (1pw) with a lowercase English character c, print REPLACE p c.
Time limit 8 seconds
Memory limit 128 MiB
Input example #1
2
3 4 3
kot
plot
5 7 3
zycie
porazka
Output example #1
YES
2
REPLACE 1 l
INSERT 1 p
NO
Source 2021 40th Petrozavodsk Programming Camp, Winter Day 1: Jagiellonian U Contest, Grand Prix of Krakow, January 29, Problem A