#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int n, m, d;
string s;
int main() {
cin >> n;
while (n--) {
cin >> m >> d >> s;
int t = -1;
for (int i = 0; i < m; i++) {
if (d > s[i] - '0') {
t = i;
break;
}
}
for (int i = 0; i < m; i++) {
if (i == t) cout << d;
cout << s[i];
}
if (t == -1) cout << d;
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int t, n;
int sx, sy, fx, fy;
inline int f(int x) {
if (x > n / 2) x = n + 1 - x ;
return x;
}
int main() {
cin >> t;
while (t--) {
cin >> n >> sx >> sy >> fx >> fy;
sx = f(sx), sy = f(sy), fx = f(fx), fy = f(fy);
cout << abs(min(sx, sy) - min(fx, fy)) << endl;
}
return 0;
}