#include <bits/stdc++.h>
using namespace std;
namespace zzc {
const int maxn = 1e5 + 5;
int t, n, ans1[maxn], ans2[maxn], cnt1, cnt2;
char a[maxn], b[maxn];
void work() {
  scanf("%d", &t);
  while (t--) {
    cnt1 = 0;
    cnt2 = 0;
    scanf("%d", &n);
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    for (int i = 1; i < n; i++) {
      if (a[i] != a[i + 1]) {
        ans1[++cnt1] = i;
      }
    }
    for (int i = 1; i < n; i++) {
      if (b[i] != b[i + 1]) {
        ans2[++cnt2] = i;
      }
    }
    if (a[n] == b[n])
      printf("%d ", cnt1 + cnt2);
    else
      printf("%d ", cnt1 + cnt2 + 1);
    for (int i = 1; i <= cnt1; i++) printf("%d ", ans1[i]);
    if (a[n] != b[n]) printf("%d ", n);
    for (int i = cnt2; i >= 1; i--) printf("%d ", ans2[i]);
    puts(" ");
  }
}
}  // namespace zzc
int main() {
  zzc::work();
  return 0;
}
