#include <bits/stdc++.h>
using namespace std;
char a[200005], b[200006];
int c[200006];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    scanf("%s %s", a + 1, b + 1);
    int cnt = 0;
    for (int i = 1; i < n; i++)
      if (a[i] != a[i + 1]) c[++cnt] = i;
    if (a[n] != b[n]) c[++cnt] = n;
    for (int i = n - 1; i >= 1; i--)
      if (b[i + 1] != b[i]) c[++cnt] = i;
    cout << cnt << " ";
    if (cnt) {
      for (int i = 1; i < cnt; i++) cout << c[i] << " ";
      cout << c[cnt] << endl;
    } else
      cout << endl;
  }
  return 0;
}
