#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int T, n;
char a[N], b[N];
vector<int> ans1, ans2;
void solve(char s[], vector<int> &g) {
  for (int i = 1; i <= n - 1; i++) {
    if (s[i] != s[i + 1]) g.push_back(i);
  }
  if (s[n] == '1') g.push_back(n);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> n >> a + 1 >> b + 1;
    ans1.clear();
    ans2.clear();
    solve(a, ans1);
    solve(b, ans2);
    int sz1 = ans1.size();
    int sz2 = ans2.size();
    printf("%d", sz1 + sz2);
    for (int i = 0; i < sz1; i++) printf(" %d", ans1[i]);
    for (int i = sz2 - 1; i >= 0; i--) printf(" %d", ans2[i]);
    printf("\n");
  }
  return 0;
}
