#include <bits/stdc++.h>
int h[4040];
std::bitset<2010> f;
int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return x;
}
char a[100010], b[100010];
int cnt1, cnt2;
int ans1[100010], ans2[100010];
int main() {
  int T = read();
  while (T--) {
    int n = read();
    gets(a), gets(b);
    a[0] -= '0', b[0] -= '0';
    if (a[0]) {
      ans1[++cnt1] = 1;
      a[0] = 0;
    }
    for (int i = 1; i < n; ++i) {
      a[i] -= '0';
      if (a[i] != a[i - 1]) {
        ans1[++cnt1] = i;
        a[i - 1] ^= 1;
      }
    }
    if (b[0]) {
      ans2[++cnt2] = 1;
      b[0] = 0;
    }
    for (int i = 1; i < n; ++i) {
      b[i] -= '0';
      if (b[i] != b[i - 1]) {
        ans2[++cnt2] = i;
        b[i - 1] ^= 1;
      }
    }
    if (a[n - 1] != b[n - 1]) {
      ans1[++cnt1] = n;
    }
    printf("%d ", cnt1 + cnt2);
    for (int i = 1; i <= cnt1; ++i) {
      printf("%d ", ans1[i]);
      ans1[i] = 0;
    }
    for (int i = cnt2; i; --i) {
      printf("%d ", ans2[i]);
      ans2[i] = 0;
    }
    puts("");
    cnt1 = cnt2 = 0;
  }
  return 0;
}
