#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int sz;
    cin >> sz;
    string str1, str2;
    cin >> str1 >> str2;
    if (str1 == str2) {
      cout << 0 << endl;
      continue;
    }
    vector<int> res1, res2;
    for (int i = 0; i < sz - 1; i++) {
      if (str1[i] != str1[i + 1]) res1.push_back(i + 1);
      if (str2[i] != str2[i + 1]) res2.push_back(i + 1);
    }
    if (str1[sz - 1] == '1') res1.push_back(sz);
    if (str2[sz - 1] == '1') res2.push_back(sz);
    cout << (res1.size() + res2.size()) << " ";
    for (auto i : res1) cout << i << " ";
    for (int i = res2.size() - 1; i >= 0; i--) cout << res2[i] << " ";
    cout << endl;
  }
  return 0;
}
