#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);
bool a[MAXN], b[MAXN];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    a[i] = (c == '1');
  }
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    b[i] = (c == '1');
  }
  bool pref = a[1];
  vector<int> flips;
  for (int i = 1; i < n; ++i) {
    if (pref == a[i + 1]) {
      continue;
    }
    flips.push_back(i);
    pref = !pref;
  }
  for (int i = n; i > 0; --i) {
    if (b[i] == pref) {
      continue;
    }
    flips.push_back(i);
    pref = !pref;
  }
  cout << flips.size() << " ";
  for (int i : flips) {
    cout << i << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(13) << fixed;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
