#include <bits/stdc++.h>
using namespace std;
template <class T>
void smin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void smax(T &a, T b) {
  a = max(a, b);
}
template <class T>
T min(vector<T> &a) {
  return *min_element(a.begin(), a.end());
}
template <class T>
T max(vector<T> &a) {
  return *max_element(a.begin(), a.end());
}
template <class T>
void print(vector<T> &a, string sep) {
  for (T el : a) cout << el << sep;
  cout << endl;
}
char nott(char x, int revs) {
  if (revs % 2 == 0) return x;
  if (x == '0')
    return '1';
  else
    return '0';
}
char charr(char x, int revs) {
  if (revs % 2 == 0)
    return x;
  else
    return nott(x, 1);
}
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  if (n == 1) {
    if (a[0] == b[0]) {
      cout << 0 << endl;
      return;
    } else {
      cout << 1 << ' ' << 1 << endl;
      return;
    }
  }
  vector<int> changes;
  int revs = 0;
  int ctr = 1;
  for (int i = n - 1; i > 0; i--) {
    if (a[0] == b[i]) {
      changes.push_back(1);
      changes.push_back(i + 1);
    } else {
      changes.push_back(i + 1);
    }
    revs++;
    if (revs % 2 == 0) {
      a[0] = nott(a[ctr], revs);
      ctr++;
    } else {
      a[0] = nott(a[n - ctr], revs);
    }
  }
  if (a[0] != b[0]) {
    changes.push_back(1);
  }
  cout << changes.size() << ' ';
  print(changes, " ");
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
