#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t, k, n, d, m, u, v;
  t = 1;
  cin >> t;
  while (t--) {
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> ans;
    deque<char> qq;
    for (int i = 0; i < n; i++) qq.push_back(s1[i]);
    bool dir = true;
    long long cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (dir) {
        char cc = qq.front();
        if (cc == s2[i]) {
          if (cnt % 2 == 0) {
            ans.push_back(1);
          }
        } else {
          if (cnt % 2) {
            ans.push_back(1);
          }
        }
        qq.pop_front();
        dir = false;
      } else {
        char cc = qq.back();
        if (cc == s2[i]) {
          if (cnt % 2 == 0) {
            ans.push_back(1);
          }
        } else {
          if (cnt % 2) {
            ans.push_back(1);
          }
        }
        qq.pop_back();
        dir = true;
      }
      ans.push_back(i + 1);
      cnt++;
    }
    cout << ans.size() << " ";
    for (auto it : ans) cout << it << " ";
    cout << "\n";
  }
  return 0;
}
