#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int _w;
char A[N], B[N];
int n, ans[N], res, l, r, t;
int get(int p) {
  if (l <= r)
    return A[l + p - 1] ^ t;
  else
    return A[l - p + 1] ^ t;
}
inline void solve(void) {
  _w = scanf("%d%s%s", &n, A + 1, B + 1), res = 0;
  l = 1, r = n, t = 0;
  for (int i = n; i; --i) {
    if (get(i) ^ B[i]) {
      if ((A[l] ^ t) == B[i]) ans[++res] = 1;
      swap(l, r), t ^= 1, ans[++res] = i;
    }
    if (r > l)
      --r;
    else
      ++r;
  }
  printf("%d ", res);
  for (int i = 1; i <= res; ++i) printf("%d ", ans[i]);
  puts("");
}
int main(void) {
  int T;
  _w = scanf("%d", &T);
  while (T--) solve();
  return 0;
}
