#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << "\n"; }
template <typename H, typename... T>
void debug_out(H h, T... t) {
  cerr << " " << (h);
  debug_out(t...);
}
int n;
string a, b;
char flip(char ch) { return (char)('0' + ('1' - ch)); }
char ch(int i, int cnt) { return (char)('0' + ((a[i] - '0' + cnt) % 2)); }
void solve() {
  cin >> n >> a >> b;
  vector<int> res;
  int first = 0;
  int last = n - 1;
  int cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (ch(last, cnt) != b[i]) {
      if (ch(first, cnt) == b[i]) {
        res.push_back(1);
        a[first] = flip(a[first]);
      }
      if (i or ch(first, cnt) != b[i]) {
        res.push_back(i + 1);
        cnt++;
        swap(first, last);
      }
    }
    if (cnt % 2) {
      last++;
    } else {
      last--;
    }
  }
  cout << res.size();
  for (auto i : res) cout << " " << i;
  cout << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
