#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;
}