#include <bits/stdc++.h>
using namespace std;
int arr1[100010], arr2[100010], ans[200020];
int ansit;
int main() {
  int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y,
      z, cnt, st, ed, fl;
  char tmp;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d", &n);
    scanf("%c", &tmp);
    for (j = 0; j < n; j++) {
      scanf("%c", &tmp);
      if (tmp == '0')
        arr1[j] = 0;
      else
        arr1[j] = 1;
    }
    scanf("%c", &tmp);
    for (j = 0; j < n; j++) {
      scanf("%c", &tmp);
      if (tmp == '0')
        arr2[j] = 0;
      else
        arr2[j] = 1;
    }
    ansit = 0;
    st = 0;
    ed = n - 1;
    fl = 0;
    for (j = n - 1; j >= 0; j--) {
      if ((arr1[ed] + fl) % 2 == arr2[j]) {
        if (st < ed)
          ed--;
        else
          ed++;
      } else {
        if ((arr1[st] + fl) % 2 != arr2[j]) {
          ans[ansit] = j + 1;
          ansit++;
          z = st;
          st = ed;
          ed = z;
          if (st < ed)
            ed--;
          else
            ed++;
          fl = 1 - fl;
        } else {
          ans[ansit] = 1;
          ansit++;
          ans[ansit] = j + 1;
          ansit++;
          z = st;
          st = ed;
          ed = z;
          if (st < ed)
            ed--;
          else
            ed++;
          fl = 1 - fl;
        }
      }
    }
    printf("%d ", ansit);
    for (j = 0; j < ansit; j++) printf("%d ", ans[j]);
    printf("\n");
  }
}
