#include <bits/stdc++.h>
char str[100005];
char str2[100005];
int solution[2 * 100005];
int steps, n;
int start, end, flipped;
void init() {
  start = 0;
  end = n - 1;
  flipped = 0;
  for (int i = 0; i < n; ++i) {
    str[i] -= '0';
    str2[i] -= '0';
  }
}
void useLast() {
  if (flipped) {
    start++;
  } else {
    end--;
  }
}
int getLast() {
  if (flipped) {
    return 1 - str[start];
  } else {
    return str[end];
  }
}
int getFirst() {
  if (flipped) {
    return 1 - str[end];
  } else {
    return str[start];
  }
}
void flip() { flipped = 1 - flipped; }
void solve() {
  steps = 0;
  init();
  int a, b;
  for (int j = n - 1; j >= 0; j--) {
    b = str2[j];
    if (b != getLast()) {
      a = getFirst();
      if (a == b) {
        solution[steps++] = 1;
      }
      solution[steps++] = j + 1;
      flip();
    }
    useLast();
  }
  printf("%d", steps);
  for (int i = 0; i < steps; ++i) {
    printf(" %d", solution[i]);
  }
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", str);
    scanf("%s", str2);
    solve();
  }
  return 0;
}
