#include <bits/stdc++.h>
using namespace std;
inline int re_ad() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}
inline bool read() {
  char ch = getchar();
  while (ch != '0' && ch != '1') ch = getchar();
  return (ch == '1');
}
int t, n;
bool A[100010], B[100010];
int cz[300010], cnt;
int to[300010];
int main() {
  register int i, j, fz, l, r, c;
  t = re_ad();
  while (t--) {
    n = re_ad();
    fz = 0;
    cnt = 0;
    l = 1;
    r = n;
    for (i = 1; i <= n; ++i) A[i] = read();
    for (i = 1; i <= n; ++i) B[i] = read();
    for (i = n; i > 1; --i) {
      if (fz)
        c = A[l] ^ fz;
      else
        c = A[r];
      if (c == B[i]) {
        if (fz)
          ++l;
        else
          --r;
        continue;
      }
      if (fz) {
        if ((A[r] ^ fz ^ 1) != B[i]) A[r] ^= 1, cz[++cnt] = 1;
      } else if ((A[l] ^ fz ^ 1) != B[i])
        A[l] ^= 1, cz[++cnt] = 1;
      cz[++cnt] = i;
      fz ^= 1;
      if (!fz)
        --r;
      else
        ++l;
    }
    A[l] ^= fz;
    if (A[l] != B[1]) cz[++cnt] = 1;
    printf("%d ", cnt);
    for (i = 1; i <= cnt; ++i) printf("%d ", cz[i]);
    putchar('\n');
  }
  return 0;
}
