#include <bits/stdc++.h>
using namespace std;
const long long Linf = 0x7f7f7f7f7f7f7f7f;
const int Inf = 0x3f3f3f3f;
int n;
string a, b;
void Prefix_Flip() {
  cin >> n >> a >> b;
  vector<int> veca, vecb;
  for (int i = 1; i < n; i++)
    if (a[i] != a[i - 1]) veca.push_back(i - 1);
  for (int i = 1; i < n; i++)
    if (b[i] != b[i - 1]) vecb.push_back(i - 1);
  if (b[n - 1] != a[n - 1]) vecb.push_back(n - 1);
  reverse(vecb.begin(), vecb.end());
  for (auto x : vecb) veca.push_back(x);
  int k = veca.size();
  cout << k << ' ';
  for (auto x : veca) cout << x + 1 << ' ';
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int _;
  cin >> _;
  while (_--) Prefix_Flip();
  return 0;
}
