#include <bits/stdc++.h>
using namespace std;
vector<int> A, B;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n;
  cin >> t;
  string a, b;
  while (t--) {
    A.clear();
    B.clear();
    cin >> n >> a >> b;
    a += "0";
    b += "0";
    for (int i = 1; i <= n; ++i)
      if (a[i] != a[i - 1]) A.push_back(i);
    for (int i = 1; i <= n; ++i)
      if (b[i] != b[i - 1]) B.push_back(i);
    reverse(B.begin(), B.end());
    cout << A.size() + B.size();
    for (int i = 0; i < A.size(); ++i) cout << " " << A[i];
    for (int i = 0; i < B.size(); ++i) cout << " " << B[i];
    cout << '\n';
  }
  return 0;
}
