#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > cn(long long int n, long long int m) {
  return vector<vector<long long int> >(n, vector<long long int>(m));
}
bool compare(char &s1, char &s2) { return s1 > s2; }
bool sortmahstyle(const pair<long long int, long long int> &a,
                  const pair<long long int, long long int> &b) {
  if (a.second > b.second) return true;
  if (a.second == b.second && a.first > b.second) return true;
  return false;
}
long long int const mod = 1e9 + 7;
long long int const inf = 1e5 + 1;
void solve() {
  long long int n;
  cin >> n;
  string A, B;
  cin >> A >> B;
  vector<long long int> ans;
  long long int cnt = (A[0] == '1') ? 1 : 0;
  for (long long int i = 0; i < n - 1; i++) {
    cnt = (A[i + 1] == '1') ? 1 : 0;
    if (A[i] == A[i + 1]) continue;
    ans.push_back(i + 1);
  }
  if (cnt == 1) ans.push_back(n);
  cnt = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    long long int state = (B[i] == '1') ? 1 : 0;
    if (state == cnt) continue;
    ans.push_back(i + 1);
    cnt ^= 1;
  }
  cout << ans.size() << " ";
  for (auto e : ans) cout << e << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
