#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
vector<long long> ans;
void solve(string& a, string& b, long long idx, long long start, long long end,
           bool flip) {
  if (idx < 0) return;
  if (start == end) {
    if (a[start] == b[idx]) {
      if (flip) ans.push_back(1);
    } else {
      if (!flip) ans.push_back(1);
    }
    return;
  }
  if (start <= end) {
    if (flip) {
      if (a[end] != b[idx]) {
        solve(a, b, idx - 1, start, end - 1, flip);
      } else {
        if (a[start] != b[idx]) ans.push_back(1);
        ans.push_back(idx + 1);
        solve(a, b, idx - 1, end, start + 1, !flip);
      }
    } else {
      if (a[end] == b[idx]) {
        solve(a, b, idx - 1, start, end - 1, flip);
      } else {
        if (a[start] == b[idx]) ans.push_back(1);
        ans.push_back(idx + 1);
        solve(a, b, idx - 1, end, start + 1, !flip);
      }
    }
  } else {
    if (flip) {
      if (a[end] != b[idx]) {
        solve(a, b, idx - 1, start, end + 1, flip);
      } else {
        if (a[start] != b[idx]) ans.push_back(1);
        ans.push_back(idx + 1);
        solve(a, b, idx - 1, end, start - 1, !flip);
      }
    } else {
      if (a[end] == b[idx]) {
        solve(a, b, idx - 1, start, end + 1, flip);
      } else {
        if (a[start] == b[idx]) ans.push_back(1);
        ans.push_back(idx + 1);
        solve(a, b, idx - 1, end, start - 1, !flip);
      }
    }
  }
}
void solve() {
  ans.clear();
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  solve(a, b, n - 1, 0, n - 1, false);
  cout << ans.size() << " ";
  for (long long& e : ans) cout << e << " ";
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
