#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> ans;
    long long cnt = 0;
    long long st = 0;
    long long en = n - 1;
    for (long long i = n - 1; i >= 0; i--) {
      char lst = s1[en];
      if (cnt % 2) lst = '0' + '1' - lst;
      if (lst == s2[i]) {
        if (cnt % 2)
          en++;
        else
          en--;
        continue;
      }
      char fst = s1[st];
      if (cnt % 2) fst = '0' + '1' - fst;
      if (fst == s2[i]) ans.push_back(1);
      ans.push_back(i + 1);
      cnt++;
      swap(st, en);
      if (cnt % 2)
        en++;
      else
        en--;
    }
    cout << ans.size() << ' ';
    for (__typeof(ans.size()) i = (0) - ((0) > (ans.size()));
         i != (ans.size()) - ((0) > (ans.size()));
         i += 1 - 2 * ((0) > (ans.size())))
      cout << ans[i] << ((i == (ans.size() - 1)) ? '\n' : ' ');
  }
  return 0;
}
