#include <bits/stdc++.h>
using namespace std;
constexpr int32_t maxn = 1e5 + 2;
char a[maxn], b[maxn];
vector<long long> ans;
inline void add(long long i) { ans.push_back(i); }
inline void convert_from_zero_to(char *a, long long n) {
  bool flip = false;
  for (long long i = n - 1; i >= 0; --i) {
    if (a[i] == flip) continue;
    flip ^= 1;
    add(i);
  }
}
void solve() {
  long long n;
  ans.clear();
  cin >> n >> a >> b;
  for (long long i = 0; i < n; ++i) {
    a[i] -= '0';
    b[i] -= '0';
  }
  convert_from_zero_to(a, n);
  reverse(ans.begin(), ans.end());
  convert_from_zero_to(b, n);
  cout << ans.size() << '\n';
  assert((long long)ans.size() <= (n << 1));
  for (long long x : ans) {
    cout << x + 1 << ' ';
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
