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