#include <bits/stdc++.h>
using namespace std;
const int nax = 1e9 + 7;
const int mod = 1e9 + 7;
const int inf = (1 << 30);
const long double PI = 3.1415926535897932384626433832795;
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  assert((int)s.size() == n && (int)t.size() == n);
  queue<int> qu;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] != s[i + 1]) {
      qu.push(i + 1);
    }
  }
  if (s[n - 1] == '1') {
    qu.push(n);
  }
  if (t[n - 1] == '1') {
    qu.push(n);
  }
  for (int i = n - 1 - 1; ~i; --i) {
    if (t[i] != t[i + 1]) {
      qu.push(i + 1);
    }
  }
  cout << qu.size() << ' ';
  while (qu.size()) {
    cout << qu.front() << ' ';
    qu.pop();
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
