#include <bits/stdc++.h>
using namespace std;
void test() {
  int N;
  string A, B;
  cin >> N >> A >> B;
  int z = 0, k = N - 1;
  vector<int> vys;
  for (int n = (0); n < (N); n++) {
    if (n % 2 == 0) {
      if (B[N - 1 - n] == A[z]) vys.push_back(1);
      vys.push_back(N - n);
      z++;
    } else {
      if (B[N - 1 - n] != A[k]) vys.push_back(1);
      vys.push_back(N - n);
      k--;
    }
  }
  cout << vys.size();
  for (auto w : vys) cout << " " << w;
  cout << "\n";
}
int main() {
  int T;
  cin >> T;
  while (T--) test();
  return 0;
}
