#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int flag = 0, inv = 0, p = 0, q = n - 1;
  vector<int> ans;
  for (int i = n - 1; i >= 0; i--) {
    if (flag == 1) {
      if ((s1[p] == s2[i] && inv == 0) || (s1[p] != s2[i] && inv == 1)) {
        p++;
        continue;
      } else {
        if ((s1[q] == s2[i] && inv == 0) || (s1[q] != s2[i] && inv == 1)) {
          ans.push_back(0);
        }
        q--;
        inv = inv ^ 1;
        ans.push_back(i);
        flag = 0;
      }
    } else {
      if ((s1[q] == s2[i] && inv == 0) || (s1[q] != s2[i] && inv == 1)) {
        q--;
        continue;
      } else {
        if ((s1[p] == s2[i] && inv == 0) || (s1[p] != s2[i] && inv == 1)) {
          ans.push_back(0);
        }
        p++;
        inv = inv ^ 1;
        ans.push_back(i);
        flag = 1;
      }
    }
  }
  cout << ans.size() << " ";
  for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << " ";
  cout << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
