#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    if (n == 1 && a[0] != b[0])
      cout << "1 1 " << endl;
    else if (n == 1 && a[0] == b[0])
      cout << 0 << endl;
    else {
      long long int l = 0, r = n - 1, p = 0;
      vector<long long int> v;
      for (i = n - 1; i >= 0; i--) {
        if (p % 2 == 1) {
          if (a[r] != b[i]) v.push_back(1);
          v.push_back(i + 1);
          r--;
        } else {
          if (a[l] == b[i]) v.push_back(1);
          v.push_back(i + 1);
          l++;
        }
        p++;
      }
      cout << v.size() << " ";
      for (i = 0; i < v.size(); i++) cout << v[i] << " ";
      cout << endl;
    }
  }
}
