#include <bits/stdc++.h>
using namespace std;
long long n;
string a, b;
long long on = 1;
void solve() {
  cin >> n >> a >> b;
  vector<long long> ans;
  long long l = 0, r = n - 1;
  long long fl = 0;
  long long re = 0;
  for (long long i = n - 1; i >= 0; i--) {
    long long cb = a[r] - '0';
    if (re) cb = a[l] - '0';
    cb ^= fl;
    long long w = b[i] - '0';
    if (cb == w) {
      if (re) {
        l++;
      } else
        r--;
      continue;
    }
    long long fi = a[l] - '0';
    if (re) fi = a[r] - '0';
    fi ^= fl;
    if (fi == w) {
      ans.push_back(1);
      ans.push_back(i + 1);
      re ^= on;
      fl ^= on;
      if (re)
        l++;
      else
        r--;
    } else {
      ans.push_back(i + 1);
      re ^= on;
      fl ^= on;
      if (re)
        l++;
      else
        r--;
    }
  }
  cout << (long long)ans.size() << "\n";
  for (auto j : ans) cout << j << " ";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }
  return 0;
}
