#include <bits/stdc++.h>
using namespace std;
int t, n, a;
string x, y;
int main(void) {
  scanf("%d", &t);
  while (t--) {
    vector<int> ans;
    scanf("%d", &n);
    cin >> x >> y;
    for (int i = 0; i < n - 1; i++)
      if (x[i] != x[i + 1]) ans.push_back(i + 1);
    char num = x[n - 1];
    for (int i = n - 1; i >= 0; i--) {
      if (y[i] == num) continue;
      ans.push_back(i + 1);
      if (num == '0')
        num = '1';
      else
        num = '0';
    }
    printf("%d ", ans.size());
    for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
