#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a < b) return b;
  return a;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
char rev(char c) {
  if (c == '0') return '1';
  return '0';
}
bool check(string a, string b, vector<long long> &ans) {
  for (int i = 0; i < ans.size(); i++) {
    long long ind = ans[i];
    for (int j = 0; j < ind; j++) {
      a[j] = rev(a[j]);
    }
    reverse(a.begin(), a.begin() + ind);
  }
  return a == b;
}
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  char c = a[0];
  for (int i = 1; i < n; i++) {
    if (a[i] != c) {
      c = a[i];
      ans.push_back(i);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (c == b[i]) continue;
    ans.push_back(i + 1);
    c = rev(c);
  }
  cout << ans.size() << " ";
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test = 0;
  cin >> test;
  while (test--) solve();
  return 0;
}
