#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<int> oper;
    for (int i = n - 1; i >= 0; --i) {
      int j = n - i;
      if (j % 2 == 1) {
        if (a[j / 2] == b[i]) oper.push_back(1);
        oper.push_back(i + 1);
      } else {
        if (a[n - j / 2] != b[i]) oper.push_back(1);
        oper.push_back(i + 1);
      }
    }
    cout << oper.size();
    for (int x : oper) cout << ' ' << x;
    cout << endl;
  }
  return 0;
}
