#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
int ans;
int res[2 * MAX + 5];
char a[MAX + 5], b[MAX + 5];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int N;
    scanf("%d", &N);
    getchar();
    scanf("%s%s", a + 1, b + 1);
    for (int i = 1; i <= N; i++) {
      a[i] = a[i] - '0';
      b[i] = b[i] - '0';
    }
    ans = 0;
    for (int i = N; i > 0; i--) {
      if (i < N) {
        int k = N - i;
        if (k & 1)
          a[1] = !a[i + 1 + k / 2];
        else
          a[1] = a[1 + k / 2];
      }
      if (!((a[1]) ^ (b[i]))) res[ans++] = 1;
      res[ans++] = i;
    }
    printf("%d%c", ans, ans ? ' ' : '\n');
    for (int i = 0; i < ans; i++)
      printf("%d%c", res[i], i == ans - 1 ? '\n' : ' ');
  }
  return 0;
}
