#include <bits/stdc++.h>
using namespace std;
int main() {
  int s;
  cin >> s;
  while (s--) {
    string a = "", b = "";
    vector<int> mp;
    int n;
    cin >> n >> a >> b;
    a += '0';
    b += '0';
    vector<int> vec1, vec2;
    for (int i = 1; i <= n; ++i) {
      if (a[i] != a[i - 1]) vec1.push_back(i);
      if (b[i] != b[i - 1]) vec2.push_back(i);
    }
    vec1.insert(vec1.end(), vec2.rbegin(), vec2.rend());
    cout << vec1.size();
    for (int i : vec1) {
      cout << ' ' << i;
    }
    cout << endl;
  }
  return 0;
}
