#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int i, j, k, n, m;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long int> dis1, dis2;
    if (n == 1) {
      if (a == b)
        cout << 0 << "\n";
      else
        cout << "1 1"
             << "\n";
      continue;
    }
    for (i = 0; i < (n - 1); i++) {
      if (a[i] != a[i + 1]) {
        dis1.emplace_back(i + 1);
      }
      if (b[i] != b[i + 1]) {
        dis2.emplace_back(i + 1);
      }
    }
    if (a[n - 1] != b[n - 1]) dis1.emplace_back(n);
    long long int ans = dis1.size() + dis2.size();
    cout << ans << " ";
    for (i = 0; i < dis1.size(); i++) cout << dis1[i] << " ";
    if (dis2.size() > 0)
      for (i = dis2.size() - 1; i >= 0; i--) cout << dis2[i] << " ";
    cout << "\n";
  }
  return 0;
}
