#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
string A, B;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, temp = 0;
    cin >> n >> A >> B;
    A += '0';
    B += '0';
    vector<long long int> V;
    for (long long int i = 0; i < n; i++) {
      if (A[i] != A[i + 1]) V.push_back(i + 1);
    }
    for (long long int i = n - 1; i >= 0; i--) {
      if (B[i] != B[i + 1]) V.push_back(i + 1);
    }
    cout << V.size() << " ";
    for (auto x : V) cout << x << " ";
    cout << "\n";
  }
  return 0;
}
