#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;
inline int lowbit(int x) { return x & (-x); }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void ex_gcd(long long a, long long b, long long &d, long long &x,
            long long &y) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    ex_gcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
inline long long qpow(long long a, long long b, long long MOD = mod) {
  long long res = 1;
  a %= MOD;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
inline long long inv(long long x, long long p) { return qpow(x, p - 2, p); }
inline long long Jos(long long n, long long k, long long s = 1) {
  long long res = 0;
  for (int i = 1; i <= n + 1; ++i) res = (res + k) % i;
  return (res + s) % n;
}
inline long long read() {
  long long f = 1;
  long long x = 0;
  char ch = getchar();
  while (ch > '9' | ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
int a[maxn], b[maxn];
long long ans[2 * maxn];
void resever(int tmp) {
  for (int i = 1; i <= tmp; i++) a[i] = !(a[i] - 48) + 48;
  for (int i = 1, j = tmp; i <= j; i++, j--) swap(a[i], a[j]);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n = read();
    for (int i = 1; i <= n; ++i) {
      scanf(" %c", &a[i]);
      a[i] -= '0';
    }
    for (int i = 1; i <= n; ++i) {
      scanf(" %c", &b[i]);
      b[i] -= '0';
    }
    int cnt = 0;
    int pos = 1;
    for (int i = 1; i <= n; ++i) {
      if (b[n - i + 1] == (a[pos] + i - 1) % 2) ans[cnt++] = 1;
      ans[cnt++] = n - i + 1;
      if (pos <= n / 2)
        pos = n - pos + 1;
      else
        pos = n - pos + 2;
    }
    printf("%d ", cnt);
    for (int i = 0; i < cnt; ++i) printf("%d ", ans[i]);
    printf("\n");
  }
}
