#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, t;
  cin >> t;
  while (t--) {
    cin >> n;
    string a, b;
    cin >> a >> b;
    if (a == b) {
      cout << 0 << '\n';
    } else {
      vector<long long> v;
      for (auto i = 0; i < n; ++i) {
        while (i + 1 < n && a[i] == a[i + 1]) ++i;
        v.push_back(i);
      }
      if (a[n - 1] == '1') v.pop_back();
      vector<long long> rev;
      for (auto i = 0; i < n; ++i) {
        while (i + 1 < n && b[i] == b[i + 1]) ++i;
        rev.push_back(i);
      }
      if (b[n - 1] == '1') rev.pop_back();
      while (!rev.empty()) {
        long long c = rev[rev.size() - 1];
        v.push_back(c);
        rev.pop_back();
      }
      cout << v.size() << ' ';
      for (auto i : v) cout << i + 1 << ' ';
      cout << '\n';
    }
  }
  return 0;
}
