#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> p;
    int left = 0, right = n - 1;
    for (int i = n - 1; i >= 0; --i) {
      if (left > right) {
        if (a[left] != b[i]) {
          p.push_back(1);
        }
        p.push_back(i + 1);
        --left;
        swap(left, right);
      } else if (left < right) {
        if (a[left] == b[i]) {
          p.push_back(1);
        }
        p.push_back(i + 1);
        ++left;
        swap(left, right);
      } else {
        if (a[left] == b[i] && n % 2 == 0)
          p.push_back(i + 1);
        else if (a[left] != b[i] && n % 2 == 1)
          p.push_back(i + 1);
      }
    }
    cout << p.size();
    for (int d : p) cout << ' ' << d;
    cout << endl;
  }
  return 0;
}
