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