#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long> ans;
    for (long long i = 0; i < n - 1; i++) {
      if (a[i] != a[i + 1]) ans.push_back(i);
    }
    if (a[n - 1] == '1') ans.push_back(n - 1);
    vector<long long> ans1;
    for (long long i = 0; i < n - 1; i++) {
      if (b[i] != b[i + 1]) ans1.push_back(i);
    }
    if (b[n - 1] == '1') ans1.push_back(n - 1);
    reverse(ans1.begin(), ans1.end());
    cout << ans.size() + ans1.size() << " ";
    for (long long i = 0; i < ans.size(); i++) cout << ans[i] + 1 << " ";
    for (long long i = 0; i < ans1.size(); i++) cout << ans1[i] + 1 << " ";
    cout << "\n";
  }
  return 0;
}
