#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n;
string a, b;
void solve() {
  cin >> n;
  cin >> a >> b;
  vector<int> res;
  int cur = a[n - 1] - '0';
  if (cur == 1) res.push_back(n);
  for (int i = n - 2; i >= 0; i--)
    if (a[i] != cur + '0') res.push_back(i + 1), cur = 1 - cur;
  reverse(res.begin(), res.end());
  cur = b[n - 1] - '0';
  vector<int> ans;
  if (cur == 1) ans.push_back(n);
  for (int i = n - 2; i >= 0; i--)
    if (b[i] != cur + '0') ans.push_back(i + 1), cur = 1 - cur;
  cout << res.size() + ans.size() << ' ';
  for (auto &v : res) cout << v << ' ';
  for (auto &v : ans) cout << v << ' ';
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
