#include <bits/stdc++.h>
using namespace std;
int rep, n, m, x, y, p;
string s, s2;
int main() {
  cin >> rep;
  while (rep) {
    rep--;
    cin >> n >> s >> s2;
    p = 0;
    vector<int> sol;
    for (int i = 0; i < n - 1; i++) {
      if (s[i] != s[i + 1]) sol.push_back(i + 1);
    }
    if (s[n - 1] == '1') sol.push_back(n);
    for (int i = n - 1; i >= 0; i--) {
      x = 0;
      y = s2[i] - '0';
      x += p;
      x %= 2;
      if (x != y) {
        sol.push_back(i + 1);
        p %= 2;
        p++;
      }
    }
    cout << sol.size() << " ";
    for (int i = 0; i < sol.size(); i++) {
      cout << sol[i] << " ";
    }
    cout << "\n\n";
  }
}
