#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (unsigned i = 0; i < v.size(); i++) in >> v[i];
  return in;
}
void solve(int T) {
  long long N;
  cin >> N;
  string a, b;
  cin >> a >> b;
  a += '0';
  b += '0';
  vector<long long> t1, t2;
  for (long long i = (1); i < (N + 1); i++) {
    if (a[i] != a[i - 1]) t1.push_back(i);
    if (b[i] != b[i - 1]) t2.push_back(i);
  }
  cout << (t1.size() + t2.size()) << " ";
  for (long long i = (0); i < (t1.size()); i++) cout << t1[i] << " ";
  reverse(t2.begin(), t2.end());
  for (long long i = (0); i < (t2.size()); i++) cout << t2[i] << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(20);
  long long T;
  cin >> T;
  int i = 1;
  while (T--) {
    solve(i);
    i++;
  }
  return 0;
}
