#include <bits/stdc++.h>
using namespace std;
const long long inf = (1LL << 60) - 1;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void solve() {
  long long n;
  cin >> n;
  vector<long long> ans;
  string a, b;
  cin >> a >> b;
  for (long long i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) {
      ans.push_back(i);
      if (a[0] == '1')
        a[0] = '0';
      else
        a[0] = '1';
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (b[i] != a[0]) {
      ans.push_back(i + 1);
      if (a[0] == '1')
        a[0] = '0';
      else
        a[0] = '1';
    }
  }
  cout << ans.size();
  for (long long i = 0; i < (1LL) * ans.size(); i++) cout << " " << ans[i];
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
