#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    s += '0';
    t += '0';
    vector<int> a, b;
    for (int i = 1; i <= n; i++) {
      if (s[i] != s[i - 1]) a.push_back(i);
      if (t[i] != t[i - 1]) b.push_back(i);
    }
    cout << a.size() + b.size() << ' ';
    for (auto it : a) cout << it << ' ';
    for (auto it = b.rbegin(); it != b.rend(); it++) cout << *it << ' ';
    cout << '\n';
  }
  return 0;
}
