#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return (f == 1) ? x : -x;
}
int REVI, REVW, n, a[1010101], b[1010101], A[1010101];
char s1[1011101], s2[1010101];
vector<int> as;
int ONE;
inline void doit(int i) { as.push_back(i); }
int REV, REVV;
signed main() {
  int T = read();
  while (T--) {
    n = read();
    scanf("%s", s1 + 1);
    scanf("%s", s2 + 1);
    for (int i = 1; i <= n; i++) {
      a[i] = s1[i] - '0', b[i] = s2[i] - '0';
      A[i] = a[i];
    }
    as.clear();
    REVW = 0;
    REV = 0;
    REVV = 1;
    ONE = a[1];
    for (int i = n; i >= 2; i--) {
      if ((a[REVV * i - REV * REVV] ^ REVW) != b[i]) {
        if (ONE != b[i]) {
          ONE = a[REVV * i - REV * REVV] ^ REVW ^ 1;
          doit(i);
          REVW ^= 1;
          REV = i + 1 - REV;
          REVV = -REVV;
        } else {
          doit(1);
          ONE = a[REVV * i - REV * REVV] ^ REVW ^ 1;
          doit(i);
          REVW ^= 1;
          REV = i + 1 - REV;
          REVV = -REVV;
        }
      }
    }
    if (ONE != b[1]) {
      doit(1);
    }
    printf("%d ", (int)as.size());
    for (auto x : as) {
      printf("%d ", x);
    }
    puts("");
  }
  return 0;
}
