#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> ans1, ans2;
    string a, b;
    cin >> a >> b;
    a = a + '0';
    b = b + '0';
    for (int i = 0; i < n; i++) {
      if (a[i] != a[i + 1]) ans1.push_back(i);
    }
    for (int i = 0; i < n; i++) {
      if (b[i] != b[i + 1]) ans2.push_back(i);
    }
    cout << ans1.size() + ans2.size() << " ";
    for (int i = 0; i < ans1.size(); i++) cout << ans1[i] + 1 << " ";
    for (int i = ans2.size() - 1; i >= 0; i--) cout << ans2[i] + 1 << " ";
    cout << "\n";
  }
  return 0;
}
