#include <bits/stdc++.h>
using namespace std;
const int M = 400001;
int n, m, k, T, ans[M];
char a[M], b[M];
int main() {
  scanf("%d", &T);
  for (; T; T--) {
    scanf("%d", &n);
    scanf("\n%s\n%s", a + 1, b + 1);
    int s = 1, t = n, B = 1, cnt = 0, tag = 0;
    for (int i = n; i; i--) {
      if ((a[t] == b[i]) ^ tag) {
        t -= B;
        continue;
      } else if ((a[s] != b[i]) ^ tag) {
        ans[++cnt] = i;
        s += B;
        swap(s, t);
        B *= -1;
        tag ^= 1;
      } else {
        ans[++cnt] = 1;
        ans[++cnt] = i;
        s += B;
        tag ^= 1;
        swap(s, t);
        B *= -1;
      }
    }
    printf("%d ", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
    printf("\n");
  }
}
