#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tests;
  cin >> tests;
  while (tests--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    a += '0';
    b += '0';
    vector<int> v1;
    vector<int> v2;
    for (int i = 1; i <= n; i++) {
      if (a[i] != a[i - 1]) v1.push_back(i);
      if (b[i] != b[i - 1]) v2.push_back(i);
    }
    for (int i = v2.size() - 1; i >= 0; i--) {
      v1.push_back(v2[i]);
    }
    cout << v1.size();
    for (int i : v1) {
      cout << " " << i;
    }
    cout << endl;
  }
  return 0;
}
