#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template class Cumsum{ public: Cumsum(vector v): v(v){ n = v.size(); v_cumsum = vector(n+1, T(0)); for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i]; } /** * v[l] + ... + v[r-1] */ T sum(int l, int r){ if(r <= l) return T(0); if(r > n) r = n; if(l < 0) l = 0; return v_cumsum[r]-v_cumsum[l]; } private: int n; vector v; vector v_cumsum; }; class KMP { public: string pattern; int plen; vector table; KMP(const string s) : pattern(s), plen((int)pattern.size()), table(plen+1){ table[0] = -1; int j = -1; for(int i = 0; i < plen; i++){ while(j >= 0 && pattern[i] != pattern[j]) j = table[j]; if(pattern[i+1] == pattern[++j]) table[i+1] = table[j]; else table[i+1] = j; } } void search(const string& text, vector& res){ int head = 0, j = 0, tlen = (int)text.size(); while(head + j < tlen){ if(pattern[j] == text[head + j] || text[head+j] == '?'){ if(++j != plen) continue; res.push_back(head); } head += j - table[j], j = max(table[j], 0); } } }; void solve(){ int n, m; cin >> n >> m; string s, t; cin >> s >> t; KMP kmp(t); vector v; kmp.search(s, v); if(v.empty()){ cout << -1 << endl; return; } vector cnt(n); for(int i = 0; i < n; i++){ if(s[i] == '?') cnt[i] = 1; } auto cumsum = Cumsum(cnt); string ans = s; for(int i: v){ if(cumsum.sum(i, i+m) == 0){ for(int j = 0; j < n; j++) { if(ans[j] == '?') ans[j] = 'a'; } cout << ans << endl; return; } } int i = v.back(); for(int j = i; j < i+m; j++){ ans[j] = t[j-i]; } for(int j = 0; j < n; j++) { if(ans[j] == '?') ans[j] = 'a'; } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }