#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void solve() {
LL n;
cin >> n;
string s, t;
cin >> s >> t;
LL cnt1 = 0, cnt2 = 0, pre = 0, aft = 0;
for (int i = 0; i < n; i++) {
if (s[i] != t[i]) {
int pos = i;
while (i < n && s[i] != t[i]) i++;
if (!cnt1) {
cnt1 = i - pos;
pre = pos;
aft = n - i;
} else if (!cnt2) {
cnt2 = i - pos;
aft = n - i;
} else {
cout << 0 << '\n';
return;
}
}
// cout << pre << ' ' << af/t << '\n';
}
LL res = 0;
if (cnt1 < cnt2) swap(cnt1, cnt2);
if (!cnt1 && !cnt2) {
res = (n - 1) * n / 2 + n;
cout << res << '\n';
} else if (!cnt2) {
if (pre) res += 2 * pre;
if (aft) res += 2 * aft;
if (cnt1 > 1) res += (cnt1 - 1) * 2;
else if (cnt1 == 1) res += ;
cout << res << '\n';
} else {
cout << 6 << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}