1. #include "bits/stdc++.h"
  2. #pragma GCC optimize("Ofast,unroll-loops")
  3. #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  4. using namespace std;
  5. using ll = long long int;
  6. mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
  7.  
  8. struct input_checker {
  9. string buffer;
  10. int pos;
  11.  
  12. const string all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  13. const string number = "0123456789";
  14. const string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  15. const string lower = "abcdefghijklmnopqrstuvwxyz";
  16.  
  17. input_checker() {
  18. pos = 0;
  19. while (true) {
  20. int c = cin.get();
  21. if (c == -1) {
  22. break;
  23. }
  24. buffer.push_back((char) c);
  25. }
  26. }
  27.  
  28. int nextDelimiter() {
  29. int now = pos;
  30. while (now < (int) buffer.size() && buffer[now] != ' ' && buffer[now] != '\n') {
  31. now++;
  32. }
  33. return now;
  34. }
  35.  
  36. string readOne() {
  37. assert(pos < (int) buffer.size());
  38. int nxt = nextDelimiter();
  39. string res;
  40. while (pos < nxt) {
  41. res += buffer[pos];
  42. pos++;
  43. }
  44. // cerr << res << endl;
  45. return res;
  46. }
  47.  
  48. string readString(int minl, int maxl, const string &pattern = "") {
  49. assert(minl <= maxl);
  50. string res = readOne();
  51. assert(minl <= (int) res.size());
  52. assert((int) res.size() <= maxl);
  53. for (int i = 0; i < (int) res.size(); i++) {
  54. assert(pattern.empty() || pattern.find(res[i]) != string::npos);
  55. }
  56. return res;
  57. }
  58.  
  59. int readInt(int minv, int maxv) {
  60. assert(minv <= maxv);
  61. int res = stoi(readOne());
  62. assert(minv <= res);
  63. assert(res <= maxv);
  64. return res;
  65. }
  66.  
  67. long long readLong(long long minv, long long maxv) {
  68. assert(minv <= maxv);
  69. long long res = stoll(readOne());
  70. assert(minv <= res);
  71. assert(res <= maxv);
  72. return res;
  73. }
  74.  
  75. void readSpace() {
  76. assert((int) buffer.size() > pos);
  77. assert(buffer[pos] == ' ');
  78. pos++;
  79. }
  80.  
  81. void readEoln() {
  82. assert((int) buffer.size() > pos);
  83. assert(buffer[pos] == '\n');
  84. pos++;
  85. }
  86.  
  87. void readEof() {
  88. assert((int) buffer.size() == pos);
  89. }
  90. };
  91.  
  92. int main()
  93. {
  94. ios::sync_with_stdio(false); cin.tie(0);
  95.  
  96. input_checker inp;
  97.  
  98. int sumn = 0, minn = 100'001, maxn = 0;
  99. int summ = 0, minm = 100'001, maxm = 0;
  100. int t = inp.readInt(1, 100'000);
  101. inp.readEoln();
  102.  
  103. while (t--) {
  104. int n = inp.readInt(1, 100'000); inp.readSpace();
  105. int m = inp.readInt(1, 100'000); inp.readEoln();
  106. sumn += n; maxn = max(maxn, n); minn = min(minn, n);
  107. summ += m; maxm = max(maxm, m); minm = min(minm, m);
  108.  
  109. string text = inp.readString(n, n); inp.readEoln();
  110. string pat = inp.readString(m, m); inp.readEoln();
  111.  
  112. int ptr = 0;
  113. for (auto &c : text) {
  114. if (ptr < m and pat[ptr] == c) ++ptr;
  115. if (ptr == m) break;
  116. if (c != '?') continue;
  117. for (int i = 0; i < 5; ++i) {
  118. if (pat[ptr] == 'a'+i) continue;
  119. c = 'a' + i;
  120. break;
  121. }
  122. }
  123. if (ptr == m) cout << "-1\n";
  124. else cout << text << '\n';
  125. }
  126. inp.readEof();
  127. assert(sumn <= 300'000);
  128. assert(summ <= 300'000);
  129.  
  130. cerr << "Sum N, M: " << sumn << ' ' << summ << '\n';
  131. cerr << "Maximum N, M: " << maxn << ' ' << maxm << '\n';
  132. cerr << "Minimum N, M: " << minn << ' ' << minm << '\n';
  133. }