#include #include #include using mint = atcoder::modint998244353; namespace atcoder { std::istream& operator>>(std::istream& in, mint& a) { long long e; in >> e; a = e; return in; } std::ostream& operator<<(std::ostream& out, const mint& a) { out << a.val(); return out; } } // namespace atcoder void solve() { int n, m; std::cin >> n >> m; std::string s, t; std::cin >> s >> t; std::reverse(s.begin(), s.end()); std::vector f0(n), f1(n), f2(n); std::vector g0(m), g1(m), g2(m); for (int i = 0; i < n; ++i) { f0[i] = (s[i] == '?') ? 0 : 1; f1[i] = f0[i] * s[i]; f2[i] = f1[i] * s[i]; } for (int j = 0; j < m; ++j) { g0[j] = 1; g1[j] = g0[j] * t[j]; g2[j] = g1[j] * t[j]; } std::vector h(n + m - 1); std::vector f2g0 = atcoder::convolution(f2, g0); std::vector f1g1 = atcoder::convolution(f1, g1); std::vector f0g2 = atcoder::convolution(f0, g2); for (int i = 0; i < n + m - 1; ++i) { h[i] += f2g0[i] - 2 * f1g1[i] + f0g2[i]; } for (int i = m - 1; i < n; ++i) { if (h[i] == 0) { for (int j = 0; j < m; ++j) { s[i - j] = t[j]; } std::replace(s.begin(), s.end(), '?', 'a'); std::reverse(s.begin(), s.end()); std::cout << s << '\n'; return; } } std::cout << -1 << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t-- > 0) { solve(); } }