#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a;
    string b;
    cin >> a;
    cin >> b;
    vector<int> v1;
    vector<int> v2;
    char s = a[0];
    for (int i = 0; i < n; i++) {
      if (a[i] != s) {
        v1.push_back(i);
        s = a[i];
      }
    }
    char s2 = b[0];
    for (int i = 0; i < n; i++) {
      if (b[i] != s2) {
        v2.push_back(i);
        s2 = b[i];
      }
    }
    if (s2 != s) v1.push_back(n);
    reverse(v2.begin(), v2.end());
    cout << v1.size() + v2.size() << " ";
    for (int i = 0; i < v1.size(); i++) cout << v1[i] << " ";
    for (int i = 0; i < v2.size(); i++) cout << v2[i] << " ";
    cout << '\n';
  }
  return 0;
}
