#include <bits/stdc++.h>
using namespace std;
bool checkbitt(long long int num, int pos);
long long int setbitt(long long int num, long long int pos);
long long int resetbitt(long long int num, int pos);
int solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    if (i == 0) continue;
    if (s[i] != s[i - 1]) {
      res.push_back(i);
    }
  }
  char ch = s[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (ch != t[i]) {
      ch = t[i];
      res.push_back(i + 1);
    }
  }
  cout << res.size() << endl;
  for (auto x : res) cout << x << " ";
  cout << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int cs = 1;
  int cn = 1;
  cin >> cs;
  while (cs--) {
    solve();
  }
}
bool checkbitt(long long int num, int pos) { return (num >> pos) & 1; }
long long int setbitt(long long int num, long long int pos) {
  return (1 << pos) | num;
}
long long int resetbitt(long long int num, int pos) {
  if (!checkbitt(num, pos))
    return num;
  else
    return (1 << pos) ^ num;
}
