#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int i, x1, x2, ct1 = 0, ct2 = 0, arr[n];
    int *ch1, *ch2;
    ch1 = (int *)malloc(sizeof(int));
    ch2 = (int *)malloc(sizeof(int));
    scanf("%1d", &arr[0]);
    x1 = arr[0];
    for (i = 1; i < n; i++) {
      scanf("%1d", &arr[i]);
      if (arr[i] != arr[i - 1]) {
        ct1++;
        ch1 = (int *)realloc(ch1, ct1 * sizeof(int));
        ch1[ct1 - 1] = i;
        x1 = arr[i];
      }
    }
    int arr2[n];
    scanf("%1d", &arr2[0]);
    x2 = arr2[0];
    for (i = 1; i < n; i++) {
      scanf("%1d", &arr2[i]);
      if (arr2[i] != arr2[i - 1]) {
        ct2++;
        ch2 = (int *)realloc(ch2, ct2 * sizeof(int));
        ch2[ct2 - 1] = i;
        x2 = arr2[i];
      }
    }
    if (x1 == arr2[n - 1])
      printf("%d ", ct1 + ct2);
    else
      printf("%d ", ct1 + ct2 + 1);
    for (i = 0; i < ct1; i++) printf("%d ", ch1[i]);
    if (x1 != arr2[n - 1]) printf("%d ", n);
    for (i = ct2 - 1; i >= 0; i--) printf("%d ", ch2[i]);
    printf("\n");
  }
}
