#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> v, c;
    for (int i = 1; i < n; i++) {
      if (s[i] != s[i - 1]) v.push_back(i);
    }
    if (s[n - 1] != t[n - 1]) v.push_back(n);
    for (int i = 1; i < n; i++) {
      if (t[i] != t[i - 1]) c.push_back(i);
    }
    reverse(c.begin(), c.end());
    cout << (int)v.size() + (int)c.size() << " ";
    for (int val : v) cout << val << " ";
    for (int val : c) cout << val << " ";
    cout << '\n';
  }
  return 0;
}
