#include <bits/stdc++.h>
int main() {
  long long int t, a = 0, b = 0, c = 0, d, i, j, k = 0, x, y, z, n, l, r, s = 0,
                   m = 0;
  scanf("%lld", &t);
  char ar[100005], br[100005];
  for (j = 0; j < t; j++) {
    scanf("%lld", &a);
    int sr[2 * a], t[a];
    scanf("%s %s", ar, br);
    for (i = 1; i < a; i++) {
      if (ar[i] != ar[i - 1]) sr[c++] = i;
    }
    if (ar[a - 1] != br[a - 1]) sr[c++] = a;
    for (i = a - 1; i >= 1; i--) {
      if (br[i] != br[i - 1]) t[k++] = i;
    }
    for (x = 0; x < k; x++) sr[c++] = t[x];
    printf("%lld ", c);
    for (i = 0; i < c; i++) printf("%d ", sr[i]);
    printf("\n");
    c = k = 0;
  }
  return 0;
}
