#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> v1;
    vector<int> v2;
    for (int i = 0; i < n - 1; i++) {
      if (s[i] != s[i + 1]) v1.push_back(i + 1);
      if (t[i] != t[i + 1]) v2.push_back(i + 1);
    }
    if (s[n - 1] == '1') v1.push_back(n);
    if (t[n - 1] == '1') v2.push_back(n);
    cout << v1.size() + v2.size() << " ";
    for (int i = 0; i < v1.size(); i++) cout << v1[i] << " ";
    for (int i = v2.size() - 1; i >= 0; i--) cout << v2[i] << " ";
    cout << endl;
  }
  return 0;
}
