#include <bits/stdc++.h>
using namespace std;
void tokenize(string str, const char delim, vector<string>& res) {
  stringstream p(str);
  string token;
  while (getline(p, token, delim)) {
    res.push_back(token);
  }
  return;
}
int N;
string str1, str2;
void test_case() {
  cin >> N >> str1 >> str2;
  vector<int> ans;
  int end = N - 1, start = 0;
  int ptr = 0;
  int flips = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (flips % 2 != 0) str1[ptr] ^= 1;
    if (str2[i] == str1[ptr]) ans.push_back(0);
    ans.push_back(i);
    ++flips;
    if (ptr == start)
      ++start, ptr = end;
    else
      --end, ptr = start;
  }
  cout << ((long long)ans.size()) << ' ';
  for (auto el : ans) cout << el + 1 << ' ';
  cout << endl;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  ;
  int tt;
  cin >> tt;
  while (tt--) {
    test_case();
  }
  return 0;
}
