#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool per_square(long double a) {
  if (a < 0) return false;
  long long sr = sqrt(a);
  return (sr * sr == a);
}
bool is_prime(long long x) {
  for (long long i = 2; i < sqrt(x) + 1; i++)
    if (x % i == 0) return false;
  return true;
}
bool sort_by_sec(const pair<long long, long long> &a,
                 const pair<long long, long long> &b) {
  return (a.second < b.second);
}
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ops1, ops2;
  a += '0';
  b += '0';
  for (long long i = 1; i < n + 1; i++) {
    if (a[i] != a[i - 1]) ops1.push_back(i);
    if (b[i] != b[i - 1]) ops2.push_back(i);
  }
  ops1.insert(ops1.end(), ops2.rbegin(), ops2.rend());
  cout << ops1.size() << " ";
  for (auto &i : ops1) cout << i << " ";
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tests = 1;
  cin >> tests;
  for (long long test = 1; test <= tests; test++) {
    solve();
  }
  return 0;
}
