Broken Life

 You are given two strings 

and of lengths and

respectively.

  • String
contains characters from the set
  • .
  • String
  • contains characters from the set
    • .

    Let

    denote the string formed by replacing all the in using the characters from the set .
    Construct such that is not a subsequence of

    .

    If multiple such

    exist, output any. If no such exists, print

    .

    Input Format

    • The first line will contain
  • - the number of test cases. Then the test cases follow.
  • The first line of each test case contains two integers
  • and - the lengths of strings and
  • respectively.
  • The second line of each test case contains string
  • .
  • The third line of each test case contains string
    • .

    Output Format

    For each test case, output any valid string

    . If no such string exists, print

    .

    Constraints

  • Sum of
  • over all test cases does not exceed
  • .
  • Sum of
  • over all test cases does not exceed
    • .

    Sample Input 1

    2
    4 2
    ?ab?
    ba
    4 2
    a??b
    ab
    

    Sample Output 1

    aabe
    -1
    

    Explanation

    Test case

    : Replace the at indices and using characters and respectively. Both the characters belong to the set .
    The string . Note that no subsequence of is equal to

    .

    Test case

    : There is no possible value of such that is not a subsequence of .
    Previous
    Next Post »