#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    a += 'M', b += 'M';
    string tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    a += tmp1, b += tmp2;
    for (int i = (1); i < n + 1; i++) a[i] -= '0', b[i] -= '0';
    vector<int> ans;
    int pos = 1;
    for (int i = (1); i < n + 1; i++) {
      if (b[n - i + 1] == (a[pos] + i - 1) % 2) ans.push_back(1);
      ans.push_back(n - i + 1);
      if (pos <= n / 2)
        pos = n - pos + 1;
      else
        pos = n - pos + 2;
    }
    cout << ans.size() << " ";
    for (auto p : ans) cout << p << " ";
    cout << '\n';
  }
  return 0;
}
