#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
vector<int> work(string s) {
  vector<int> res;
  for (int i = 0; i < s.length(); ++i) {
    if (i != s.length() - 1 && s[i] != s[i + 1]) {
      res.push_back(i + 1);
    }
  }
  if (s[s.length() - 1] == '0') {
  } else {
    res.push_back(s.length());
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  vector<int> res, res2;
  res = work(s1);
  res2 = work(s2);
  reverse(res2.begin(), res2.end());
  cout << res.size() + res2.size() << " ";
  for (auto it : res) cout << it << " ";
  for (auto it : res2) cout << it << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
