#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    vector<int> v;
    for (int i = 1; i < n; i++) {
      if (a[i] != a[i - 1]) {
        v.push_back(i);
      }
    }
    if (a[n - 1] != b[n - 1]) v.push_back(n);
    for (int i = n - 1; i > 0; i--) {
      if (b[i] != b[i - 1]) {
        v.push_back(i);
      }
    }
    cout << v.size() << " ";
    for (auto i : v) {
      cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}
