- #include "bits/stdc++.h"
- #pragma GCC optimize("Ofast,unroll-loops")
- #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
- using namespace std;
- using ll = long long int;
- mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
-
- struct input_checker {
- string buffer;
- int pos;
-
- const string all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- const string number = "0123456789";
- const string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- const string lower = "abcdefghijklmnopqrstuvwxyz";
-
- input_checker() {
- pos = 0;
- while (true) {
- int c = cin.get();
- if (c == -1) {
- break;
- }
- buffer.push_back((char) c);
- }
- }
-
- int nextDelimiter() {
- int now = pos;
- while (now < (int) buffer.size() && buffer[now] != ' ' && buffer[now] != '\n') {
- now++;
- }
- return now;
- }
-
- string readOne() {
- assert(pos < (int) buffer.size());
- int nxt = nextDelimiter();
- string res;
- while (pos < nxt) {
- res += buffer[pos];
- pos++;
- }
- // cerr << res << endl;
- return res;
- }
-
- string readString(int minl, int maxl, const string &pattern = "") {
- assert(minl <= maxl);
- string res = readOne();
- assert(minl <= (int) res.size());
- assert((int) res.size() <= maxl);
- for (int i = 0; i < (int) res.size(); i++) {
- assert(pattern.empty() || pattern.find(res[i]) != string::npos);
- }
- return res;
- }
-
- int readInt(int minv, int maxv) {
- assert(minv <= maxv);
- int res = stoi(readOne());
- assert(minv <= res);
- assert(res <= maxv);
- return res;
- }
-
- long long readLong(long long minv, long long maxv) {
- assert(minv <= maxv);
- long long res = stoll(readOne());
- assert(minv <= res);
- assert(res <= maxv);
- return res;
- }
-
- void readSpace() {
- assert((int) buffer.size() > pos);
- assert(buffer[pos] == ' ');
- pos++;
- }
-
- void readEoln() {
- assert((int) buffer.size() > pos);
- assert(buffer[pos] == '\n');
- pos++;
- }
-
- void readEof() {
- assert((int) buffer.size() == pos);
- }
- };
-
- int main()
- {
- ios::sync_with_stdio(false); cin.tie(0);
-
- input_checker inp;
-
- int sumn = 0, minn = 100'001, maxn = 0;
- int summ = 0, minm = 100'001, maxm = 0;
- int t = inp.readInt(1, 100'000);
- inp.readEoln();
-
- while (t--) {
- int n = inp.readInt(1, 100'000); inp.readSpace();
- int m = inp.readInt(1, 100'000); inp.readEoln();
- sumn += n; maxn = max(maxn, n); minn = min(minn, n);
- summ += m; maxm = max(maxm, m); minm = min(minm, m);
-
- string text = inp.readString(n, n); inp.readEoln();
- string pat = inp.readString(m, m); inp.readEoln();
-
- int ptr = 0;
- for (auto &c : text) {
- if (ptr < m and pat[ptr] == c) ++ptr;
- if (ptr == m) break;
- if (c != '?') continue;
- for (int i = 0; i < 5; ++i) {
- if (pat[ptr] == 'a'+i) continue;
- c = 'a' + i;
- break;
- }
- }
- if (ptr == m) cout << "-1\n";
- else cout << text << '\n';
- }
- inp.readEof();
- assert(sumn <= 300'000);
- assert(summ <= 300'000);
-
- cerr << "Sum N, M: " << sumn << ' ' << summ << '\n';
- cerr << "Maximum N, M: " << maxn << ' ' << maxm << '\n';
- cerr << "Minimum N, M: " << minn << ' ' << minm << '\n';
- }