#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m, k, i, j, count = 0, sum = 0, maxi = 0, mini = 1e18, flag = 0;
  cin >> n;
  vector<long long> res;
  vector<char> temp;
  string a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0 << "\n";
    return;
  }
  if (n == 1 && a[0] != b[0]) {
    cout << 1 << " " << 1 << "\n";
    return;
  }
  for (i = 0; i < n / 2; i++) {
    temp.push_back(a[i]);
    if (a[n - i - 1] == '1')
      temp.push_back('0');
    else
      temp.push_back('1');
  }
  if (n % 2) temp.push_back(a[n / 2]);
  i = 0;
  j = n - 1;
  while (j > 0) {
    if (temp[i] == b[j]) {
      res.push_back(0);
      res.push_back(j);
    } else
      res.push_back(j);
    j--;
    i++;
  }
  if (j == 0) {
    if (temp[i] == b[j])
      ;
    else
      res.push_back(0);
  }
  cout << res.size() << " ";
  for (i = 0; i < res.size(); i++) {
    cout << res[i] + 1 << " ";
  }
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
