#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7, N1 = 1e7 + 5;
void solve() {
  long long n, cnt = 0;
  vector<long long> v;
  cin >> n;
  string a, b;
  cin >> a >> b;
  a += '1';
  b += '1';
  for (long long i = 0; i < n; i++) {
    if (a[i] != a[i + 1]) v.push_back(i + 1);
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (b[i] != b[i + 1]) v.push_back(i + 1);
  }
  if (a == b)
    cout << 0;
  else {
    cout << v.size() << " ";
    for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  }
  cout << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t1 = 1;
  cin >> t1;
  while (t1--) {
    solve();
  }
}
