#include <bits/stdc++.h>
using namespace std;
int testcase = 1;
const int MAXN = 1e6 + 10;
int n, m, k, c;
int tmp, tmp1, tmp2, tmp3;
int res;
vector<int> v;
string a, b;
void solve() {
  vector<int> va;
  char pre = a[0];
  for (int i = 1; i < n; i++) {
    if (pre != a[i]) va.push_back(i - 1);
    pre = a[i];
  }
  int std = a[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (std != b[i]) {
      va.push_back(i);
      if (std == '0')
        std = '1';
      else
        std = '0';
    }
  }
  printf("%d", va.size());
  for (auto i : va) {
    printf(" %d", i + 1);
  }
  printf("\n");
}
int main() {
  scanf("%d", &testcase);
  while (testcase--) {
    scanf("%d", &n);
    cin >> a >> b;
    solve();
  }
  return 0;
}
