#include <bits/stdc++.h>
using namespace std;
int maxsize = 200001;
double power(float x, int y) {
  float temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
void solve() {
  long long int n;
  string a, b;
  cin >> n >> a >> b;
  vector<int> ops1, ops2;
  a += '0';
  b += '0';
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) ops1.push_back(i);
    if (b[i] != b[i - 1]) ops2.push_back(i);
  }
  ops1.insert(ops1.end(), ops2.rbegin(), ops2.rend());
  cout << ops1.size();
  for (int x : ops1) {
    cout << ' ' << x;
  }
  cout << '\n';
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
}
