#include<bits/stdc++.h>
using namespace std;
#define int long long
int t, n1, m1;
string s11, s22;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
bool judge(string s1, string s2, int n, int m) {
int i = 0, j = 0, ans = 0;
bool f = 0;
while (j < m) {
if (i >= n) {
cout << i << " " << j << "\n";
int l = m - j;
int p = i - l;
int u = j;
bool flag = 1;
for (int o = 0; o < l; o++) {
if (s1[p + o] != s2[u + o]) {
flag = 0;
break;
}
}
if (flag) return true;
else return false;
} else {
if (s1[i] == s2[j]) {
if (f) {
ans++;
f = 0;
}
i++;
j++;
} else {
j++;
f = 1;
}
}
}
if (ans >= 2) return false;
else return true;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
cin >> n1 >> m1;
cin >> s11 >> s22;
if (n1 == m1) {
if (s11 == s22) cout << "Yes\n";
else cout << "No\n";
continue;
} else {
if (judge(s11, s22, n1, m1)) cout << "Yes\n";
else cout << "No\n";
}
}
return 0;
}