#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, k, t, a[N], b[N], c[N];
char sa[N], sb[N];
void solve(int l, int r) {
  if (l == r) {
    if ((a[l] ^ t) != b[1]) c[++k] = 1;
    return;
  }
  int now = r, m = abs(r - l) + 1, dir = l < r ? -1 : 1, tmp = m;
  while (now - dir != l && (a[now] ^ t) == b[tmp]) now += dir, tmp--;
  if (now - dir == l) return;
  if (now == l) {
    c[++k] = 1;
    return;
  }
  if ((a[l] ^ t) == b[tmp]) c[++k] = 1, a[l] ^= 1;
  t ^= 1, c[++k] = abs(l - now) + 1;
  solve(now, l - dir);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s%s", &n, sa + 1, sb + 1);
    k = t = 0;
    for (int i = 1; i <= n; i++) a[i] = sa[i] - '0', b[i] = sb[i] - '0';
    solve(1, n);
    printf("%d", k);
    for (int i = 1; i <= k; i++) printf(" %d", c[i]);
    puts("");
  }
}
