#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long inf = 1e18;
long long m_inf = INT_MIN;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::fixed);
  std::cout.precision(9);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    a += '0';
    b += '0';
    vector<long long> ans1, ans2;
    for (long long i = 0; i < n; i++) {
      if (a[i] != a[i + 1]) {
        ans1.push_back(i + 1);
      }
      if (b[i] != b[i + 1]) ans2.push_back(i + 1);
    }
    reverse(ans2.begin(), ans2.end());
    cout << ans1.size() + ans2.size() << ' ';
    for (long long i = 0; i < ans1.size(); i++) cout << ans1[i] << ' ';
    for (long long i = 0; i < ans2.size(); i++) cout << ans2[i] << ' ';
    cout << '\n';
  }
}
