#include <bits/stdc++.h>
using namespace std;
long long big = 1000000007;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int x = 1;
    if (a[0] == '0') x = 0;
    vector<int> ret(0);
    for (int i = 0; i < n - 1; i += 1) {
      if (a[i] != a[i + 1]) ret.push_back(i + 1), x = 1 - x;
    }
    if (x) ret.push_back(n);
    stack<int> stk;
    x = 1;
    if (b[0] == '0') x = 0;
    for (int i = 0; i < n - 1; i += 1) {
      if (b[i] != b[i + 1]) x = 1 - x, stk.push(i + 1);
    }
    if (x) stk.push(n);
    cout << ret.size() + stk.size() << " ";
    if (ret.size()) {
      for (int i = 0; i < ret.size(); i += 1) cout << ret[i] << " ";
    }
    if (stk.size()) {
      while (!stk.empty()) {
        cout << stk.top() << " ";
        stk.pop();
      }
    }
    cout << '\n';
  }
  return 0;
}
