#include <bits/stdc++.h>
using namespace std;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const int M = 1e8;
const int N = 2e6;
const char dc[4] = {'D', 'R', 'U', 'L'};
int n, fail[N], occd[N];
char str[N];
void solve() {
  int n;
  string a, b;
  cin >> n >> a >> b;
  a += '0', b += '0';
  vector<int> ans;
  if (a == b) {
    cout << 0 << endl;
    return;
  }
  for (int i = 0; i < n; i++)
    if (a[i] != a[i + 1]) ans.push_back(i + 1);
  for (int i = n - 1; i >= 0; i--)
    if (b[i] != b[i + 1]) ans.push_back(i + 1);
  cout << ans.size() << " ";
  for (auto i : ans) cout << i << " ";
  cout << endl;
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
