#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, i;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans_a, ans_b;
    int pre;
    for (i = 0; i < n - 1; i++) {
      if (a[i] != a[i + 1]) {
        ans_a.push_back(i + 1);
      }
    }
    if (a[n - 1] == '0') ans_a.push_back(n);
    for (i = 0; i < n - 1; i++) {
      if (b[i] != b[i + 1]) {
        ans_b.push_back(i + 1);
      }
    }
    if (b[n - 1] == '0') ans_b.push_back(n);
    for (i = ans_b.size() - 1; i >= 0; i--) {
      ans_a.push_back(ans_b[i]);
    }
    cout << ans_a.size() << " ";
    if (ans_a.size() > 0)
      for (int x : ans_a) cout << x << " ";
    cout << "\n";
  }
  return 0;
}
