#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool d = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') d = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return d ? x : -x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar('0' + x % 10);
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void writep(long long x) {
  write(x);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 1e5 + 5;
char s[N], t[N];
int a[N], b[N], pos[N];
vector<long long> v;
int main() {
  int T = read();
  while (T--) {
    int n = read();
    scanf("%s%s", s + 1, t + 1);
    v.clear();
    for (int i = (int)(1); i <= (int)(n); i++)
      a[i] = s[i] - '0', b[i] = t[i] - '0';
    bool d = 0;
    int l = 1, r = n;
    for (int i = (int)(n); i >= (int)(1); i--) {
      if (!d) {
        if ((a[r] ^ d) == b[i]) {
          r--;
          continue;
        }
        if ((a[l] ^ d) == b[i]) a[l] ^= 1, v.push_back(1);
        v.push_back(i);
        l++;
        d ^= 1;
      } else {
        if ((a[l] ^ d) == b[i]) {
          l++;
          continue;
        }
        if ((a[r] ^ d) == b[i]) a[r] ^= 1, v.push_back(1);
        v.push_back(i);
        r--;
        d ^= 1;
      }
    }
    cout << (int)v.size() << " ";
    for (auto x : v) writep(x);
    puts("");
  }
}
