#include <stdio.h>
//#include <conio.h>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <sstream>
using namespace std;
typedef long long LL;
int k;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> k;
for (int i = 0; i < k; i++) {
int n;
string s, t;
vector<pair<int, int>> res;
cin >> n >> s >> t;
for (int i = 0; i < n - 1; i++)
if (s[i] != t[i]) {
int co = 0, id = -1;
for (int j = i + 1; j < n; j++)
if (s[j] == t[i])
co = 1, id = j;
if (co) {
res.push_back(pair<int, int>(id, n-1));
swap(s[id], t[n-1]);
res.push_back(pair<int, int>(i, n-1));
swap(s[i], t[n-1]);
}
else
{
int co = 0, id = -1;
for (int j = i + 1; j < n; j++)
if (t[j] == t[i])
co = 1, id = j;
if (co) {
res.push_back(pair<int, int>(i, id));
swap(s[i], t[id]);
}
else
break;
}
}
if (s == t) {
cout << "Yes\n" << res.size() << "\n";
for (int i = 0; i < res.size(); i++)
cout << res[i].first +1<< " " << res[i].second +1<< "\n";
}
else
cout << "No\n";
}
//_getch();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8vI2luY2x1ZGUgPGNvbmlvLmg+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgTEw7CmludCBrOwppbnQgbWFpbigpC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