#include <bits/stdc++.h>
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    int n;
    scanf("%d", &n);
    static char s[100000 + 5];
    scanf("%s", s);
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) a[i] = s[i] - '0';
    scanf("%s", s);
    std::vector<int> b(n);
    for (int i = 0; i < n; ++i) b[i] = s[i] - '0';
    std::vector<int> ops;
    for (int i = 0, l = 0, r = n - 1; i < n; ++i) {
      if (i % 2 == 0) {
        if (a[l] == b[n - 1 - i]) {
          ops.emplace_back(1);
        }
        ops.emplace_back(n - i);
        ++l;
      } else {
        if (a[r] != b[n - 1 - i]) {
          ops.emplace_back(1);
        }
        ops.emplace_back(n - i);
        --r;
      }
    }
    printf("%d", ops.size());
    for (int x : ops) printf(" %d", x);
    puts("");
  }
}
