#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long T, n, m;
vector<long long> ans;
char s[N], t[N];
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    ans.clear();
    cin >> n >> s + 1 >> t + 1;
    vector<long long> ans;
    long long c = n, rev = 0, p = 1;
    for (long long i = n; i >= 1; i--) {
      if ((s[p] - '0') == ((t[i] - '0') ^ rev)) ans.push_back(1);
      ans.push_back(c--), p = n - p + 1;
      if (p <= n / 2) ++p;
      rev = 1 - rev;
    }
    cout << ans.size() << " ";
    for (auto i : ans) cout << i << " ";
    cout << '\n';
  }
  return 0;
}
