#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 5;
int pivot, sign;
int n;
string a, b;
int f(int x) { return pivot + sign * x; }
int g(int x) { return (x - pivot) / sign; }
void solve() {
  scanf("%d", &n);
  cin >> a >> b;
  a = '#' + a;
  b = '#' + b;
  pivot = 0;
  sign = 1;
  vector<int> vec;
  int did = 0;
  for (int i = n; i > 0; --i) {
    if ((a[g(i)] ^ did) == b[i]) {
      continue;
    }
    if ((a[g(1)] ^ did) == b[i]) {
      a[g(1)] ^= 1;
      vec.push_back(1);
    }
    did ^= 1;
    vec.push_back(i);
    pivot = i + 1 - pivot;
    sign *= -1;
  }
  printf("%d\n", (int)vec.size());
  for (int x : vec) {
    printf("%d ", x);
  }
  printf("\n");
}
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    solve();
  }
  return 0;
}
