#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
void INPUT() {}
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<int> ans;
  vector<int> op;
  for (int i = 0; i <= n - 2; i++) {
    if (a[i] != a[i + 1]) ans.push_back(i);
    if (b[i] != b[i + 1]) op.push_back(i);
  }
  if (a[n - 1] != b[n - 1]) ans.push_back(n - 1);
  int siz = ans.size() + op.size();
  cout << siz << " ";
  int siz1 = ans.size();
  int siz2 = op.size();
  for (int i = 0; i <= siz1 - 1; i++) cout << (ans[i] + 1) << " ";
  for (int i = siz2 - 1; i >= 0; i--) cout << (op[i] + 1) << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  INPUT();
  int t;
  t = 1;
  cin >> t;
  for (int i = 0; i <= t - 1; i++) {
    solve();
  }
  return 0;
}
