#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
char a[N], b[N];
void solve() {
  vector<int> v;
  int i = 0, j = n - 1;
  bool inv = false;
  for (int k = n - 1; k >= 0; --k) {
    if (inv) {
      if (a[i] != b[k])
        i++;
      else {
        if (a[j] != b[k]) v.push_back(1);
        inv ^= 1;
        v.push_back(j - i + 1);
        j--;
      }
    } else {
      if (a[j] == b[k])
        j--;
      else {
        if (a[i] == b[k]) v.push_back(1);
        inv ^= 1;
        v.push_back(j - i + 1);
        i++;
      }
    }
  }
  printf("%d", v.size());
  for (auto x : v) printf(" %d", x);
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%s%s", &n, a, b);
    solve();
  }
  return 0;
}
