#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 100;
const int maxn = 1e6;
const int MAXL = sqrt(1e9) + 1;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int n;
char s[N], t[N];
int a[2 * N], len = 0;
void solve() {
  n = read();
  len = 0;
  scanf("%s%s", s + 1, t + 1);
  for (int i = 2; i <= n; i++)
    if (s[i] != s[i - 1]) a[++len] = i - 1;
  int c = s[n] - '0';
  for (int i = n; i >= 1; i--) {
    if (t[i] - '0' != c) {
      a[++len] = i;
      c ^= 1;
    }
  }
  printf("%d ", len);
  for (int i = 1; i <= len; i++) printf("%d ", a[i]);
  printf("\n");
}
int main() {
  int T;
  scanf("%d", &T);
  int tt = 0;
  while (T--) {
    solve();
  }
  return 0;
}
