#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n"); #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using mint = modint998244353; using vm = vector; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string s1, s2; cin >> s1 >> s2; vm a1(n), a2(n), a3(n); rep(i, 0, n) { int c = s1[i] == '?' ? 0 : s1[i] - 'a' + 1; a1[i] = c; a2[i] = c * c; a3[i] = c * c * c; } vm b0(m, 1), b1(m), b2(m); rep(i, 0, m) { int c = s2[m - 1 - i] - 'a' + 1; b0[i] = 1; b1[i] = c; b2[i] = c * c; } auto c1 = convolution(a1, b2); auto c2 = convolution(a2, b1); auto c3 = convolution(a3, b0); vm c0(n + m - 1); rep(i, 0, n + m - 1) c0[i] = c1[i] - 2 * c2[i] + c3[i]; int ans = -1; rep(k, 0, n - m + 1) { if (c0[m - 1 + k] == 0) ans = k; } if (ans == -1) { cout << -1 << "\n"; } else { rep(i, 0, m) s1[i + ans] = s2[i]; rep(i, 0, n) cout << (s1[i] == '?' ? 'a' : s1[i]); cout << "\n"; } } }